def post(self): source_key = self.request.get("key") source = Source.get(source_key) if source: source.lock = True source.put() try: s = urlfetch.fetch(url=source.path) if s.status_code == 200: d = feedparser.parse(s.content) source.title = d.feed.title source.link = d.feed.link for item in source.item_set: item.delete() for item in d.entries: i = Item(title=item.title, path=item.link, source=source) if "description" in item: i.excerpt = item.description else: i.excerpt = item.title # i.published = item.updated_parsed i.put() except: print "error" finally: source.lock = False source.put()
def get(self): sources = Source.all() items = Item.all() json = simplejson.dumps({"sources": [s.to_dict() for s in sources], "items": [i.to_dict() for i in items]}) self.response.out.write(json)