-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
241 lines (217 loc) · 8.54 KB
/
login.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ADD MEME FOR EVERY EMOTIONNNNNNNN!!!!!!!!!
from google.appengine.api import users
from google.appengine.ext import ndb
import webapp2
import jinja2
import os
from datetime import datetime, timedelta
import time
# from datetime import datetime
#from html import HTML
JINJA_ENV = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions = ['jinja2.ext.autoescape'],
autoescape =True
)
DESCRIPTION = {
'I laughed': {'feeling': 'joyful',
'color': '#02BCB8',
'index': 1},
'I feel energetic': {'feeling':'joyful',
'color': '#05ABC0',
'index': 1},
'I smiled': {'feeling': 'joyful',
'color':'#025D9C',
'index': 1},
'I feel confident': {'feeling': 'powerful',
'color': '#97D4D1',
'index': 1},
'I feel appreciated': {'feeling': 'powerful',
'color':'#6BB9C6',
'index': 1},
'I feel valuable': {'feeling': 'powerful',
'color':'#5D4E4F',
'index': 1},
'I am thankful': {'feeling': 'peaceful',
'color': '#3C9BD1',
'index': 1},
'I am content': {'feeling':'peaceful',
'color':'#486476',
'index': 1},
'I feel relaxed': {'feeling': 'peaceful',
'color':'#B4A893',
'index': 1},
'I feel burnt out': {'feeling':'sad',
'color':'#F1C131',
'index': -1},
'I am homesick': {'feeling':'sad',
'color':'#F1DD48',
'index': -1},
'I feel like an imposter': {'feeling':'sad',
'color':'#F1AD48',
'index': -1},
'I am annoyed': {'feeling':'mad',
'color':'#F1AD7C',
'index': -1},
'I am cranky': {'feeling':'mad',
'color': '#F1ADA1',
'index': -1},
'I feel betrayed': {'feeling': 'mad',
'color':'#EDADC3',
'index': -1},
'I am embarassed': {'feeling':'scared',
'color':'#FBDDCE',
'index': -1},
'I feel vulnerable': {'feeling':'scared',
'color':'#AED8BD',
'index': -1},
'I feel helpless': {'feeling': 'scared',
'color':'#BED85E',
'index': -1},
}
class Feelings(ndb.Model):
chosen_emotion = ndb.StringProperty();
chosen_intensity = ndb.IntegerProperty();
chosen_reason = ndb.StringProperty();
chosen_time = ndb.DateTimeProperty();
user = ndb.StringProperty();
#p = Feelings(chosen_emotion = "angry", chosen_intensity = 7, chosen_reason="I hate my life", chosen_time="September 7")
#p.put();
class FrontPageHandler(webapp2.RequestHandler):
def get(self):
content = JINJA_ENV.get_template('templates/frontpage.html')
user = users.get_current_user()
if user:
start_link = "/homepage"
else:
start_link = users.create_login_url('/homepage')
self.response.write(content.render(start_link = start_link))
class MainPage(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
logout_url = users.create_logout_url('/homepage')
greeting = 'Welcome! (<a href="{}">sign out</a>)'.format(
logout_url)
self.redirect('/homepage')
else:
login_url = users.create_login_url('/homepage')
greeting = '<a href="{}">Sign in</a>'.format(login_url)
self.response.write(
'<html><body>{}</body></html>'.format(greeting))
class AdminPage(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
if users.is_current_user_admin():
self.response.write('You are an administrator.')
else:
self.response.write('You are not an administrator.')
else:
self.response.write('You are not logged in.')
class homePage(webapp2.RequestHandler):
def get(self):
content = JINJA_ENV.get_template('templates/homepage.html')
logout_url = users.create_logout_url('/')
signout = 'Sign Out'
link = logout_url
self.response.write(content.render(emotions=DESCRIPTION, signout=signout, link=link))
class EmotionHandler(webapp2.RequestHandler):
def dispatch(self):
my_emotion = self.request.get('emotion')
logout_url = users.create_logout_url('/')
signout = 'Sign Out'
link = logout_url
#self.response.out.write('The emotion entered was: ' + my_emotion)
emotionpage = JINJA_ENV.get_template('templates/emotionpage.html')
self.response.write(emotionpage.render(emotion=my_emotion, color = DESCRIPTION[my_emotion]['color'], link=link, signout=signout))
class aboutpageHandler(webapp2.RequestHandler):
def get(self):
about_template = JINJA_ENV.get_template('templates/about.html')
self.response.write(about_template.render())
class dailyLog(webapp2.RequestHandler):
def post(self):
answer = self.request.get('answer')
intensityAnswer = int(self.request.get('intensityAnswer'))
my_emotion = self.request.get('my_emotion')
time = datetime.now()
# time = datetime.strftime(time, '%H:%M')
#time = self.timestamp.strftime('%Y-%m-%d %H:%M:%S')
#self.response.write(answer)
EmotionData = Feelings(chosen_reason =answer,chosen_intensity =intensityAnswer, chosen_emotion=my_emotion, chosen_time=time, user = users.get_current_user().user_id())
#e = Feelings(chosen_emotion = "sad", chosen_intensity = 3)
#e.put()
EmotionData.put()
#time.sleep(0.5)
self.redirect('/dailylog')
def get(self):
table_template = JINJA_ENV.get_template('templates/table/index.html')
today = datetime.today()
date = datetime(today.year,today.month,today.day)
print date
logout_url = users.create_logout_url('/')
signout = 'Sign Out'
link = logout_url
tableData = Feelings.query(
ndb.AND(Feelings.chosen_time >= date,
Feelings.chosen_time < date + timedelta(days=1), Feelings.user == users.get_current_user().user_id())).order(Feelings.chosen_time)
self.response.write(table_template.render(tableData = tableData, link=link,signout=signout))
class totalHistory(webapp2.RequestHandler):
def get(self):
table_template = JINJA_ENV.get_template('templates/table/indexhistory.html')
logout_url = users.create_logout_url('/')
signout = 'Sign Out'
link = logout_url
tableData = Feelings.query(
Feelings.user == users.get_current_user().user_id()).order(Feelings.chosen_time)
self.response.write(table_template.render(tableData = tableData, link=link,signout=signout))
class StyleHandler(webapp2.RequestHandler):
def get(self):
with open('templates/logs.css', 'r') as f:
self.response.write(f.read())
class dailyGraphHandler(webapp2.RequestHandler):
def get(self):
logout_url = users.create_logout_url('/')
signout = 'Sign Out'
link = logout_url
xAxis = []
yAxis = []
user = users.get_current_user()
current_date = datetime.now().replace(hour=0, minute=0, second=0)
my_todays_entries = (Feelings.query()
.filter(ndb.AND(
Feelings.user == user.user_id(),
Feelings.chosen_time >= current_date,
))
.order(Feelings.chosen_time)
.fetch())
#allTimes = Feelings.query().filter(Feelings.user == user.user_id())
#index = DESCRIPTION[my_emotion]['index']
for entry in my_todays_entries:
#print(time.chosen_time)
print(datetime.strftime(entry.chosen_time, '%H:%M'))
#print(chosen_intensity)
index = DESCRIPTION[entry.chosen_emotion]['index']
xAxis.append(datetime.strftime(entry.chosen_time, '%H:%M'))
yAxis.append(index*entry.chosen_intensity)
#data = [-1,3,-15,2,7,26,82,172,312,433]
dailygraph = JINJA_ENV.get_template('templates/dailygraph.html')
self.response.write(
dailygraph.render(
xAxis = xAxis,
yAxis=yAxis,
link=link,
signout=signout))
app = webapp2.WSGIApplication([
('/', FrontPageHandler),
('/login', MainPage),
('/homepage', homePage),
('/admin', AdminPage),
('/emotion', EmotionHandler),
('/history', totalHistory),
# ('/calendar', CalendarHandler),
# ('/about', aboutpageHandler),
('/logs.css', StyleHandler),
('/dailylog', dailyLog),
('/dailygraph', dailyGraphHandler)
], debug=True)