| Index: updater.py |
| =================================================================== |
| --- updater.py (revision 10) |
| +++ updater.py (working copy) |
| @@ -4,29 +4,33 @@ |
| import md5 |
| import wsgiref.handlers |
| import url_lookup |
| +import re |
| from google.appengine.api import urlfetch |
| from google.appengine.ext import db |
| from google.appengine.ext import webapp |
| - |
| class Digest(db.Model): |
| '''An entry in the SB list''' |
| hash = db.StringProperty(required=True) |
| - |
| class HandleUpdate(webapp.RequestHandler): |
| '''Handles /update request.''' |
| def post(self): |
| - data = self.request.get("data") |
| - count = 0 |
| - for hash in data.split(','): |
| - if Digest.gql("WHERE hash = :1", hash).get() is None: |
| - digest = Digest(hash=hash) |
| - digest.put() |
| - count += 1 |
| + data = self.request.get('data') |
| + add_count, del_count = 0, 0 |
| - logging.info("Added %d digests." % count) |
| + 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
|
| + 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
|
| + 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
|
| + if op == '+' and digest is None: |
| + Digest(hash=hash).put() |
| + add_count += 1 |
| + elif op == '-' and digest is not None: |
| + digest.delete() |
| + del_count += 1 |
|
Panayiotis
2008/05/16 22:24:49
else logging.warning ...
|
| + logging.info('Added %d digests. Removed %d digests' % (add_count, del_count)) |
| + |
| def main(): |
| application = webapp.WSGIApplication( |
| [('/update', HandleUpdate)], |
| @@ -34,5 +38,5 @@ |
| wsgiref.handlers.CGIHandler().run(application) |
| -if __name__ == "__main__": |
| +if __name__ == '__main__': |
| main() |