-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
365 lines (277 loc) · 12.4 KB
/
Copy pathmain.py
File metadata and controls
365 lines (277 loc) · 12.4 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import webapp2
import os
import jinja2
import json
import random
import HappyCloud
from HappyCloud import Happy
from HappyCloud import Usertemp
from google.appengine.api import urlfetch
from google.appengine.api import users
jinja_current_dir = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
def get_message():
message_list=['Why not try to reframe your events positively today?',
'How about focusing on what you did instead on what you achieved today :)',
'Is there something you could be grateful for today? It could be the air, your health, family, all the things we often take for granted',
'Why not take a moment to reflect? How would your 5 year old self see you right now? How about yourself when your 85? What about the you of now? Then ask why.',
'After this, how about doing something you said you would try out "Someday". Do it today :)',
'How about taking a moment to appreciate yourself today? All the simple and beautiful things about you, your smile , the energy you bring, your kindess. We are often the harshest critics of ourselves.']
return(random.choice(message_list))
def get_goals():
message_list= ['Take away the complaint that "I have been harmed" and the harm is taken away with it',
'Unless it affects the common good, why worry about others?',
'Tommorow soons becomes today, years foward to years past. Be your own salvation while you can.',
'How hot or cold is 30 degrees? Similarly, how good was your day today? :) ',
'If you asked around, it would be hard to find many who can confidently say "I like myself!". Do you like yourself? If not, whats stopping you other than yourself?',
'Unhappiness is often something we choose for ourselves. Today, why not make the concious choice to start trying to be happy instead!',
'Be it in sucess or rejection there is progress. Only in indecision do we stagnate']
return(random.choice(message_list))
#global Happymessage = str(get_message())
#global Goals = str(get_goals())
class MainHandler(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
userchecker = Usertemp.query(Usertemp.Userkey == str(users.get_current_user())).fetch()
if len(userchecker)== 0:
Userinit = Usertemp(
Userkey = str(users.get_current_user()),
Counter = 0,
# Surveycomplete = 0
#How to prevent this from resetting all the time?
)
Userinit.put()
self.redirect("/DataInput")
else:
if user:
# self.response.write("To be or not to be")
self.redirect("/HappyInterface")
else:
# self.response.write("You are not logged in")
self.redirect("/nouser")
class MainPage(webapp2.RequestHandler):
def get(self):
print("1")
print(get_message())
print("2")
print('Mainhandlerhello')
start_template = jinja_current_dir.get_template("templates/Interface.html")
Icons = {
}
self.response.write(start_template.render(Icons))
class HappySurvey(webapp2.RequestHandler):
def get(self):
start_template = jinja_current_dir.get_template("templates/Survey.html")
self.response.write(start_template.render())
def post(self):
start_template = jinja_current_dir.get_template("templates/Survey.html")
self.response.write(start_template.render())
class HappyInput(webapp2.RequestHandler):
def post(self):
#Placeholder location for survey classifcation input
username = str(users.get_current_user())
Agegrp = self.request.get('Age-Group')
Regiongrp = self.request.get('Region')
print("Regiongrp", Regiongrp)
Surveyresult = HappyCloud.Happy(
User = username,
UserAge = Agegrp,
UserRegion = Regiongrp
)
Surveyresult.put()
print(self.request)
# print(Surveyresult)
print("Hi we are here")
#1. Retrieve surveyresults
#2. Put surveyresults w user
#2. Fetch Surveyresults when inputting new data
#3. Input Surveyresults w Happyinput
user = Usertemp.query(Usertemp.Userkey == str(users.get_current_user())).fetch()
usercurrent = user[0]
#Get userlogin infoi
#Use user login info id to get students
#Take the first element of students to remove the array
#Increase the counter of the first student +=1 and save it to database in put()
unlockbutton = ""
if usercurrent.Counter >= 3:
unlockbutton = "submit"
else:
unlockbutton = "hidden"
#print(Happy.query(Happy.User == str(users.get_current_user())).fetch())
print('OK')
#Happy.query returns nothing
#Possibility 1 : Usersurvey not put() properly
#Possibility 2 : THe query is looking for the wrong thing
template_vars = {
'status': unlockbutton,
'Wellness_Messages' : get_message(),
'happy' : usercurrent.Counter,
'Happy_goals' : get_goals()
}
start_template = jinja_current_dir.get_template("templates/input_page.html")
self.response.write(start_template.render(template_vars))
class HappyInputClone(webapp2.RequestHandler):
def post(self):
user = Usertemp.query(Usertemp.Userkey == str(users.get_current_user())).fetch()
# UserSurveyall = Happy.query()
Usersurvey = Happy.query(Happy.User == str(users.get_current_user())).fetch()
Userinfo = Usersurvey[0]
usercurrent = user[0]
Happythought1 = self.request.get('Happy_thought1')
username = str(users.get_current_user())
Userager = Userinfo.UserAge
Userregioner = Userinfo.UserRegion
if Happythought1 != "":
Renamed = HappyCloud.Happy(
User = username,
# Identity = surveyresults
input1 = Happythought1,
UserAge = Userager,
UserRegion = Userregioner
)
usercurrent.Counter += 1
usercurrent.put()
Renamed.put()
unlockbutton = ""
if usercurrent.Counter >= 3:
unlockbutton = "submit"
else:
unlockbutton = "hidden"
#Get userlogin infoi
#Use user login info id to get students
#Take the first element of students to remove the array
#Increase the counter of the first student +=1 and save it to database in put()
print('OK')
template_vars = {
'status': unlockbutton,
'happy' : usercurrent.Counter,
'Happy_goals' : get_goals(),
'Wellness_Messages' : get_message(),
}
start_template = jinja_current_dir.get_template("templates/input_page.html")
self.response.write(start_template.render(template_vars))
class HappyRetreive(webapp2.RequestHandler):
def post(self):
user = Usertemp.query(Usertemp.Userkey == str(users.get_current_user())).fetch()
username = str(users.get_current_user())
Happythought1 = self.request.get('Happy_thought1')
username = str(users.get_current_user())
if Happythought1 != "":
Happythought1 = self.request.get('Happy_thought1')
Happy = HappyCloud.Happy(
User = username,
# Identity = surveyresults
input1 = Happythought1
)
usercurrent = user[0]
usercurrent.Counter = 0
usercurrent.put()
start_template = jinja_current_dir.get_template("templates/Readthoughts.html")
happy_query = HappyCloud.Happy.query()
happy = happy_query.fetch()
Usernamer = users.get_current_user()
template_vars = {
'Username' : Usernamer,
'happy' : happy,
}
self.response.write(start_template.render(template_vars))
class HappyLibrary(webapp2.RequestHandler):
def get(self):
results_template = jinja_current_dir.get_template('templates/library.html')
Userperm = Happy.query(Happy.User == str(users.get_current_user())).fetch()
print("Hello")
def Number():
noomber = random.randint(0,len(Userperm)-1)
return noomber
Happythought1 = self.request.get('Happy_thought1')
unlockbutton = ""
done = True
Usernewer1 = Userperm[Number()]
Usernewer2 = Userperm[Number()]
Usernewer3 = Userperm[Number()]
while str(Usernewer1.input1) == "None":
Usernewer1 = Userperm[Number()]
while str(Usernewer2.input1) == "None":
Usernewer2 = Userperm[Number()]
while str(Usernewer3.input1) == "None":
Usernewer3 = Userperm[Number()]
new22 = str(Usernewer1.input1)
new33 = str(Usernewer2.input1)
new44 = str(Usernewer3.input1)
#Ensure input is not = ""
#OR if input is "" refresh new22 until input retrieved not ""
template_vars = {
'happy1' : new22,
'happy2' : new33,
'happy3' : new44
}
self.response.write(results_template.render(template_vars))
class HappyLibraryRand(webapp2.RequestHandler):
def get(self):
results_template = jinja_current_dir.get_template('templates/library.html')
Userperm = Happy.query(Happy.User == str(users.get_current_user())).fetch()
print('Hello')
def Number(mylist):
noomber = random.randint(0,len(mylist)-1)
return noomber
Happythought1 = self.request.get('Happy_thought1')
unlockbutton = ""
Usernewer = Userperm[Number(Userperm)]
#Placeholder location for survey classifcation input
username = str(users.get_current_user())
Agegrp = self.request.get('Age-Group')
Regiongrp = self.request.get('Region')
Surveyresult = HappyCloud.Happy(
User = username,
UserAge = Agegrp,
UserRegion = Regiongrp
)
print(Agegrp)
print(Regiongrp)
Userany = Happy.query().filter(Happy.User!=username).fetch()
print(Userperm)
current_user = Happy.query().filter(Happy.User==username).fetch()[0]
print(current_user.UserAge)
print(current_user.UserRegion)
result = []
for user in Userany:
if user.UserAge == current_user.UserAge and user.UserRegion == current_user.UserRegion:
result.append(user)
print(result)
Result1 = result[Number(result)]
Result2 = result[Number(result)]
Result3 = result[Number(result)]
while str(Result1.input1) == "None":
Result1 = result[Number(result)]
while str(Result2.input1) == "None":
Result2 = result[Number(result)]
while str(Result2.input1) == "None":
Result3 = result[Number(result)]
# while Usernewer1.Agegrp != Randomuserlist.Agegrp:
# done = False
# for x in Userperm:
# if Agegrp == x.UserAge and Regiongrp == x.UserRegion:
# print(x.input1)
template_vars = {
'happy1' : Result1.input1,
'happy2' : Result2.input1,
'happy3' : Result3.input1
}
self.response.write(results_template.render(template_vars))
class NoUserHandler(webapp2.RequestHandler):
def get(self):
login_url = users.create_login_url("/")
self.response.write("Please log in. <a href="+ login_url + ">Login There</a>")
app = webapp2.WSGIApplication([
('/',MainHandler),
('/DataInput',HappySurvey),
('/HappyInterface',MainPage),
('/Happy', HappyInput),
('/Happy2', HappyInputClone),
('/Happier',HappyRetreive),
('/Ownlibrary', HappyLibrary),
('/library', HappyLibraryRand),
('/nouser', NoUserHandler)
], debug=True)