This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.py
51 lines (41 loc) · 1.44 KB
/
update.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
#!/usr/bin/env python
import wsgiref.handlers
import os
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users
from fearcon.db import *
class ChangeUserLevel(webapp.RequestHandler):
def post(self):
if users.get_current_user():
level = UserLevel.get_by_key_name( users.get_current_user().email() )
new_level = int( self.request.get('level') )
if not level:
level = UserLevel( None, users.get_current_user().email() )
level.user = users.get_current_user()
level.nick = level.user.nickname()
level.level = new_level
level.put()
self.response.out.write('OK')
class ChangeTotalLevel(webapp.RequestHandler):
def post(self):
old_level = int( self.request.get('old_level') )
new_level = int( self.request.get('new_level') )
avg = AverageLevel.get_or_insert( 'global' )
if old_level == 0:
avg.count += 1
avg.total += new_level
else:
total = avg.total
total -= old_level
total += new_level
avg.total = total
avg.put()
self.response.out.write('OK')
def main():
application = webapp.WSGIApplication([('/update_user', ChangeUserLevel),
('/update_total', ChangeTotalLevel)],
debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()