-
Notifications
You must be signed in to change notification settings - Fork 5
/
vocably.py
67 lines (55 loc) · 1.75 KB
/
vocably.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
from bottle import route, run, debug, template, request, static_file, redirect
from utils import vocably_oauth as oauth, score, definition, database
# Landing Page
@route('/')
def home():
output = template('home')
return output
@route('/words.json')
def wordsdict():
# Get words for user
user_email = oauth.user_email()
newwords = score.choose_words(user_email)
word_defs = {w:definition.definition(w) for w in newwords}
#word_defs = {"word1":"def1", "word2":"def2", "word3":"def3"}
return word_defs
@route('/words')
def words():
output = template('words', word_defs=wordsdict())
return output
@route('/login')
def login():
print "Logging in a user: redirecting to Google"
redirect(oauth.authorization_url())
@route('/logout')
def logout():
oauth.deauthorize()
@route('/oauth2callback')
def login_callback():
print "Login callback from Google"
if request.query.error:
print "There was an error: '%s'" % request.query.error
print "Redirecting back to root"
redirect('/')
else:
print "Successfully acquired an authentication token"
oauth.authorize(request.query.code)
database.create_user(oauth.user_email(), 0)
redirect('/emails')
@route('/emails')
def fetch_mail():
email_text = oauth.fetch_mail()
print "Got a bunch of email text"
score.score_user(oauth.user_email(), email_text)
redirect('/words')
# Static Files
@route('/css/:path#.+#', name='css')
def css(path):
return static_file(path, root='css')
@route('/img/:path#.+#', name='img')
def img(path):
return static_file(path, root='img')
@route('/js/:path#.+#', name='js')
def js(path):
return static_file(path, root='js')
run(host='0.0.0.0', port=8080, debug=True, reloader=True)