forked from warunsl/twitsent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorangeanno.py
executable file
·97 lines (86 loc) · 3.03 KB
/
orangeanno.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python
import flask
from flask import Flask
from flask import render_template
#import pymongo
#import random
#import re
#import urlparse
#import json
#from config import *
from collections import defaultdict
MAX_ANNOTATIONS = 26
#for setting up the host name
import subprocess
import sys
host = subprocess.check_output('hostname').strip()
try:
dns = subprocess.check_output('dnsdomainname').strip()
if dns:
host = host + '.' + dns
else:
host = subprocess.check_output('hostname -i').strip()
except OSError:
pass #this happens when you are on a computer not set up as a server
app = Flask(__name__)
app.secret_key = 'orangeannotation123'
css = '/static/orange.css'
@app.route("/")
def start():
#blob = flask.request.cookies
#blob = flask.request.environ
#if the user is already logged in:
# if 'sessionid' in flask.session:
# if flask.session.get('count') > MAX_ANNOTATIONS:
# return flask.redirect(flask.url_for("logout"))
# else:
# return flask.redirect(flask.url_for("annotate"))
# #if the user is trying to log in
# elif flask.request.args.get('cmd')=="login":
# return flask.redirect(flask.url_for("login"))
# else:
return render_template('welcome.html', next="/login")#, blob=blob)
@app.route("/annotate")
def annotate():
#blob = flask.request.cookies
blob = flask.request.environ
sessionid = flask.session.get('sessionid')
count = flask.session.get('count')
count += 1
flask.session['count'] = count
if flask.session.get('count') > MAX_ANNOTATIONS:
return flask.redirect(flask.url_for("logout"))
return render_template('annotate.html',
next="/annotate",
#css=css,
#blob=blob,
sessionid=sessionid,
count=count-1)
@app.route("/login")
def login():
#blob = flask.request.cookies
blob = flask.request.environ
if not flask.request.args.get('sessionid'):
#set username, session id, and count=0 in cookie
import uuid
flask.session['sessionid'] = uuid.uuid4()
flask.session['count'] = 0
return flask.redirect(flask.url_for('annotate'))
else:
#return render_template('login.html', css=css)#, blob=blob)
return flask.redirect(flask.url_for('annotate'))
@app.route("/logout")
def logout():
#blob = flask.request.cookies
blob = flask.request.environ
sessionid = flask.session.get('sessionid')
count = flask.session.get('count')
#return flask.redirect(flask.url_for('dispatch'))
if flask.request.args.get('cmd') == "restart":
flask.session.pop('count', None)
flask.session.pop('sessionid', None)
return flask.redirect(flask.url_for('start'))
return render_template('logout.html', css=css,sessionid=sessionid)#, blob=blob)
if __name__ == '__main__':
#app.run(host="homebrew.usc.edu", debug=True)
app.run(host='0.0.0.0', debug=True)