Mercurial > hg > Feedworm
changeset 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 | db35ab7753f0 |
children | b8d209fdad14 |
files | FeedEntry.py FeedUpdater.py |
diffstat | 2 files changed, 28 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/FeedEntry.py Sat Jul 24 03:11:06 2010 +0200 +++ b/FeedEntry.py Wed Jul 28 20:30:34 2010 +0200 @@ -10,6 +10,16 @@ result = session.query(FeedEntry).filter(FeedEntry.id == id) return result.first() + @staticmethod + def create(entry): + new = FeedEntry() + new.id = entry.id + new.link = entry.link + new.title = entry.title + new.updated = entry.updated_parsed + new.summary = entry.summary + return new + def __init__(self): self.create_timestamp = datetime.now() self.read = 0 @@ -30,4 +40,4 @@ self.read = 1 def markUnread(self): - self.read = 0 \ No newline at end of file + self.read = 0
--- 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)