-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexamples.py
39 lines (27 loc) · 999 Bytes
/
examples.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
from datetime import datetime
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from livecount import counter
from livecount.counter import LivecountCounter
from livecount.counter import PeriodType
def count(name):
counter.load_and_increment_counter(name)
def advanced_count(name):
counter.load_and_increment_counter(name, datetime.now(), period_types=[PeriodType.DAY, PeriodType.WEEK], namespace="tweet", delta=1)
class MainHandler(webapp.RequestHandler):
def get(self):
try:
name = "visitor"
counter.load_and_increment_counter(name)
except:
logging.info(repr(error))
self.response.out.write('Visitor: ' + str(counter.load_and_get_count(name)))
def main():
application = webapp.WSGIApplication(
[
('/examples', MainHandler),
], debug=True)
wsgiref.handlers.CGIHandler().run(application)
if __name__ == '__main__':
main()