| OLD | NEW |
|---|---|
| 1 import logging | 1 import logging |
|
Panayiotis
2008/05/16 22:24:49
move all these changes to display/handler_update.p
| |
| 2 import os | 2 import os |
| 3 import urlparse | 3 import urlparse |
| 4 import md5 | 4 import md5 |
| 5 import wsgiref.handlers | 5 import wsgiref.handlers |
| 6 import url_lookup | 6 import url_lookup |
| 7 import re | |
| 7 from google.appengine.api import urlfetch | 8 from google.appengine.api import urlfetch |
| 8 from google.appengine.ext import db | 9 from google.appengine.ext import db |
| 9 from google.appengine.ext import webapp | 10 from google.appengine.ext import webapp |
| 10 | |
| 11 | 11 |
| 12 class Digest(db.Model): | 12 class Digest(db.Model): |
| 13 '''An entry in the SB list''' | 13 '''An entry in the SB list''' |
| 14 hash = db.StringProperty(required=True) | 14 hash = db.StringProperty(required=True) |
| 15 | 15 |
| 16 | |
| 17 class HandleUpdate(webapp.RequestHandler): | 16 class HandleUpdate(webapp.RequestHandler): |
| 18 '''Handles /update request.''' | 17 '''Handles /update request.''' |
| 19 def post(self): | 18 def post(self): |
| 20 data = self.request.get("data") | 19 data = self.request.get('data') |
| 21 count = 0 | 20 add_count, del_count = 0, 0 |
| 22 for hash in data.split(','): | |
| 23 if Digest.gql("WHERE hash = :1", hash).get() is None: | |
| 24 digest = Digest(hash=hash) | |
| 25 digest.put() | |
| 26 count += 1 | |
| 27 | 21 |
| 28 logging.info("Added %d digests." % count) | 22 for m in re.finditer('([+-])([a-zA-Z0-9]{32})', data): |
|
Panayiotis
2008/05/16 22:24:49
a-fA-F
also lowercase before adding / looking up
| |
| 23 op, hash = m.group(1), m.group(2) | |
|
Panayiotis
2008/05/16 22:24:49
what if this doesn't match? let's log and continue
| |
| 24 digest = Digest.gql('WHERE hash = :1', hash).get() | |
|
Panayiotis
2008/05/16 22:24:49
name this digests, and instead of get() do get(100
| |
| 25 if op == '+' and digest is None: | |
| 26 Digest(hash=hash).put() | |
| 27 add_count += 1 | |
| 28 elif op == '-' and digest is not None: | |
| 29 digest.delete() | |
| 30 del_count += 1 | |
|
Panayiotis
2008/05/16 22:24:49
else logging.warning ...
| |
| 31 | |
| 32 logging.info('Added %d digests. Removed %d digests' % (add_count, del_count) ) | |
| 29 | 33 |
| 30 def main(): | 34 def main(): |
| 31 application = webapp.WSGIApplication( | 35 application = webapp.WSGIApplication( |
| 32 [('/update', HandleUpdate)], | 36 [('/update', HandleUpdate)], |
| 33 debug=True) | 37 debug=True) |
| 34 wsgiref.handlers.CGIHandler().run(application) | 38 wsgiref.handlers.CGIHandler().run(application) |
| 35 | 39 |
| 36 | 40 |
| 37 if __name__ == "__main__": | 41 if __name__ == '__main__': |
| 38 main() | 42 main() |
| OLD | NEW |