Permalink
Browse files

Fix example

  • Loading branch information...
1 parent ba46e4c commit 905c023228ebf2021dd0b8ee61cd74c366b8054e @simontaotw simontaotw committed Jul 11, 2011
Showing with 33 additions and 9 deletions.
  1. +3 −4 app.yaml
  2. +28 −3 examples.py
  3. +2 −2 livecount/counter.py
View
@@ -19,13 +19,12 @@ handlers:
script: livecount/counter_admin.py
login: admin
-- url: /livecount/get_counter
- script: livecount/counter_admin.py
- login: admin
-
- url: /livecount/.*
script: livecount/counter.py
login: admin
+
+- url: /examples
+ script: examples.py
# For convenience / demo only
# redirects to counter admin page
View
@@ -1,14 +1,39 @@
from datetime import datetime
-import logging
+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, 1)
+ 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", 1)
+ 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()
View
@@ -89,7 +89,7 @@ def PartialKeyName(period_type, period, name):
return period_type + ":" + scoped_period + ":" + name
-def load_and_get_count(name, namespace='default', period_type='day', period=datetime.now()):
+def load_and_get_count(name, namespace='default', period_type='all', period=datetime.now()):
# Try memcache first
partial_key = LivecountCounter.PartialKeyName(period_type, period, name)
count = memcache.get(partial_key, namespace=namespace)
@@ -98,8 +98,8 @@ def load_and_get_count(name, namespace='default', period_type='day', period=date
if count is None:
# See if this counter already exists in the datastore
full_key = LivecountCounter.KeyName(namespace, period_type, period, name)
+ logging.info("full_key: " + full_key)
record = LivecountCounter.get_by_key_name(full_key)
- count = None
# If counter exists in the datastore, but is not currently in memcache, add it
if record:
count = record.count

0 comments on commit 905c023

Please sign in to comment.