diff FeedUpdater.py @ 62:abc0516a1c0c

FeedEntry provides a static method for creating new entries: better modularization and support for working with the class in interactive mode. FeedUpdater's normalize method is a module function now, again for ease of use in interactive scenarios
author dirk@xanthippe.ping.de
date Wed, 28 Jul 2010 20:30:34 +0200
parents dcee24702dd7
children 97c4e94f99cf
line wrap: on
line diff
--- a/FeedUpdater.py	Sat Jul 24 03:11:06 2010 +0200
+++ b/FeedUpdater.py	Wed Jul 28 20:30:34 2010 +0200
@@ -13,8 +13,8 @@
     for feed in allFeeds:
         try:
             FeedUpdater(session, feed).update()
-        except FeedUpdateException:
-            log.warn("problems while updating feed " + feed.rss_url)
+        except FeedUpdateException, fue:
+            log.warn("problems while updating feed " + feed.rss_url + ": " + str(fue))
         session.commit()
 
 def findFeedsToUpdate(session):
@@ -28,6 +28,19 @@
     
     FeedUpdater(session, newFeed).update()
 
+def normalize(entry):
+    if not hasattr(entry, "id"):
+        entry.id = entry.link
+    if not hasattr(entry, "updated_parsed"):
+        entry.updated_parsed = datetime.today()
+    else:
+        entry.updated_parsed = datetime(*entry.updated_parsed[:6])
+    if not hasattr(entry, "summary"):
+        if hasattr(entry, "content"):
+            entry.summary = entry.content[0].value
+        else:
+            entry.summary = ""
+
 class FeedUpdater(object):
     def __init__(self, session, feed):
         self.session = session
@@ -47,28 +60,13 @@
         return result
 
     def processEntry(self, entry):
-        self.normalize(entry)
+        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
-        if not hasattr(entry, "updated_parsed"):
-            entry.updated_parsed = datetime.today()
-        else:
-            entry.updated_parsed = datetime(*entry.updated_parsed[:6])
-        if not hasattr(entry, "summary"):
-            entry.summary = ""
     
     def createFeedEntry(self, entry):
-        new = FeedEntry()
-        new.id = entry.id
-        new.link = entry.link
-        new.title = entry.title
-        new.updated = entry.updated_parsed
-        new.summary = entry.summary
+        new = FeedEntry.create(entry)
         new.feed = self.feed
         self.session.add(new)