添加 stanza 统计功能
[gaetalk.git] / stat.py
blobd1ab89dc1ce4eb4090593e6ec8e49b253795068a
1 #!/usr/bin/env python2
2 # vim:fileencoding=utf-8
4 import datetime
5 import config
6 from google.appengine.api import memcache
7 from google.appengine.api import mail
8 from google.appengine.ext import webapp
9 from google.appengine.ext.webapp.util import run_wsgi_app
11 class Stat(webapp.RequestHandler):
12 def get(self):
13 time = datetime.datetime.now() - datetime.timedelta(hours=1)
14 time = time.strftime('%Y-%m-%d_%H')
15 msg = []
16 for type in ('message', 'presence'):
17 count = memcache.get('%s_%s' % (type, time))
18 if count is None:
19 count = '0'
20 msg.append('%s: %s' % (type, count))
21 msg = '\n'.join(msg)
22 mail.send_mail(sender='"GAE stat" <stat@%s.appspotmail.com>' % config.appid,
23 to="Admin <%s>" % config.root,
24 subject="Stats for %s in %s" % (config.appid, time),
25 body=msg)
26 self.response.out.write(u'OK.'.encode('utf-8'))
28 application = webapp.WSGIApplication(
30 ('/_admin/stat', Stat),
32 debug=True)
34 def main():
35 run_wsgi_app(application)
37 if __name__ == "__main__":
38 main()