# HG changeset patch # User Dirk Olmes # Date 1272517482 -7200 # Node ID 72dfae8658995985cc5acf0eb717bec4073b6861 # Parent bdd1296a4b8c015c24aafce604751bcb66ca5a41 better logging when updating feeds, handle entries that have no id diff -r bdd1296a4b8c -r 72dfae865899 FeedUpdater.py --- a/FeedUpdater.py Thu Apr 29 06:47:47 2010 +0200 +++ b/FeedUpdater.py Thu Apr 29 07:04:42 2010 +0200 @@ -5,8 +5,8 @@ import feedparser import logging -STATUS_OK = 200 -logger = logging.getLogger("FeedUpdater") +STATUS_ERROR = 400 +log = logging.getLogger("FeedUpdater") def updateAllFeeds(session): allFeeds = session.query(Feed) @@ -14,7 +14,7 @@ try: FeedUpdater(session, feed).update() except FeedUpdateException: - logger.warn("problems while updating feed " + feed.rss_url) + log.warn("problems while updating feed " + feed.rss_url) session.commit() def createNewFeed(url, session): @@ -23,6 +23,7 @@ newFeed = Feed(title, url) session.add(newFeed) session.commit() + FeedUpdater(newFeed).update() session.commit() @@ -32,21 +33,27 @@ self.feed = feed def update(self): + log.info("updating " + self.feed.rss_url) result = self.getFeed() for entry in result.entries: self.processEntry(entry) def getFeed(self): result = feedparser.parse(self.feed.rss_url) - if result["status"] is not STATUS_OK: + if result["status"] >= STATUS_ERROR: raise FeedUpdateException() return result def processEntry(self, entry): + self.normalize(entry) feedEntry = FeedEntry.findById(entry.id, self.session) if feedEntry is None: self.createFeedEntry(entry) + def normalize(self, entry): + if not hasattr(entry, "id"): + entry.id = entry.link + def createFeedEntry(self, entry): new = FeedEntry() new.id = entry.id diff -r bdd1296a4b8c -r 72dfae865899 util.py --- a/util.py Thu Apr 29 06:47:47 2010 +0200 +++ b/util.py Thu Apr 29 07:04:42 2010 +0200 @@ -15,7 +15,7 @@ def createSession(): databaseUrl = loadDatabaseUrl() - engine = create_engine(databaseUrl,echo=True) + engine = create_engine(databaseUrl,echo=False) Mapping.createMapping(engine) SessionMaker = sessionmaker(bind = engine) session = SessionMaker()