Mercurial > hg > Feedworm
changeset 167:a3c945ce434c
adjust the sqlalchemy backend to the changes in AbstractFeedUpdater
author | dirk |
---|---|
date | Mon, 05 Sep 2011 19:39:08 +0200 |
parents | 04c3b9796b89 |
children | f4708d38419c |
files | backend/AbstractFeedUpdater.py backend/sqlalchemy/Feed.py backend/sqlalchemy/FeedUpdater.py backend/sqlalchemy/SqlAlchemyBackend.py |
diffstat | 4 files changed, 19 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/AbstractFeedUpdater.py Sat Sep 03 04:12:35 2011 +0200 +++ b/backend/AbstractFeedUpdater.py Mon Sep 05 19:39:08 2011 +0200 @@ -13,11 +13,6 @@ Subclasses need to implement creating and storing the new feed entries. ''' - @staticmethod - def parseFeed(url): - proxy = ProxyHandler( {"http":"http://your.proxy.here:8080/"} ) - return feedparser.parse(url, handlers = [proxy]) - def __init__(self, preferences): self.preferences = preferences @@ -25,8 +20,8 @@ self.feed = feed log.info("updating " + feed.rss_url) result = self._retrieveFeed() + self._setFeedTitle(result) self._processEntries(result) - self._setFeedTitle(result) def _retrieveFeed(self): if self.preferences.isProxyConfigured(): @@ -34,6 +29,7 @@ proxyHandler = ProxyHandler({"http" : proxyUrl}) result = feedparser.parse(self.feed.rss_url, handlers=[proxyHandler]) else: + # when updating to python3 see http://code.google.com/p/feedparser/issues/detail?id=260 result = feedparser.parse(self.feed.rss_url) # bozo flags if a feed is well-formed. # if result["bozo"] > 0:
--- a/backend/sqlalchemy/Feed.py Sat Sep 03 04:12:35 2011 +0200 +++ b/backend/sqlalchemy/Feed.py Mon Sep 05 19:39:08 2011 +0200 @@ -7,9 +7,9 @@ def all(session): return session.query(Feed).order_by(Feed.title).all() - def __init__(self, title, rss_url): + def __init__(self, rss_url, title=None): + self.rss_url = rss_url self.title = title - self.rss_url = rss_url # default: update every 60 minutes self.update_interval = 60 self.incrementNextUpdateDate() @@ -44,7 +44,7 @@ def markAllEntriesRead(self): for entry in self.entries: entry.markRead() - - def takeChangesFrom(self, dict): - for key in dict.keys(): - setattr(self, key, dict[key]) + + def takeChangesFrom(self, changes): + for key in changes.keys(): + setattr(self, key, changes[key])
--- a/backend/sqlalchemy/FeedUpdater.py Sat Sep 03 04:12:35 2011 +0200 +++ b/backend/sqlalchemy/FeedUpdater.py Mon Sep 05 19:39:08 2011 +0200 @@ -1,18 +1,17 @@ +from Feed import Feed +from FeedEntry import FeedEntry from backend.AbstractFeedUpdater import AbstractFeedUpdater, FeedUpdateException from datetime import datetime -from Feed import Feed -from FeedEntry import FeedEntry -import feedparser import logging log = logging.getLogger("FeedUpdater") -def updateAllFeeds(session): +def updateAllFeeds(preferences, session): allFeeds = findFeedsToUpdate(session) for feed in allFeeds: try: - FeedUpdater(session, feed).update() + FeedUpdater(preferences, session).update(feed) except FeedUpdateException, fue: log.warn("problems while updating feed " + feed.rss_url + ": " + str(fue)) session.commit() @@ -20,22 +19,10 @@ def findFeedsToUpdate(session): return session.query(Feed).filter(Feed.next_update < datetime.now()) -def createNewFeed(url, session): - # when updating to python3 see http://code.google.com/p/feedparser/issues/detail?id=260 - result = feedparser.parse(url) - if result.has_key("title"): - title = result["feed"].title - else: - title = url - newFeed = Feed(title, url) - session.add(newFeed) - - FeedUpdater(session, newFeed).update(result) - class FeedUpdater(AbstractFeedUpdater): - def __init__(self, session, feed): - AbstractFeedUpdater.__init__(self, feed) + def __init__(self, preferences, session): + AbstractFeedUpdater.__init__(self, preferences) self.session = session def _processEntry(self, entry):
--- a/backend/sqlalchemy/SqlAlchemyBackend.py Sat Sep 03 04:12:35 2011 +0200 +++ b/backend/sqlalchemy/SqlAlchemyBackend.py Mon Sep 05 19:39:08 2011 +0200 @@ -75,14 +75,17 @@ def createFeed(self, url): try: - FeedUpdater.createNewFeed(url, self.session) + newFeed = Feed(url) + self.session.add(newFeed) + + FeedUpdater.FeedUpdater(self.preferences(), self.session).update(newFeed) self.session.commit() except AttributeError as ae: self.session.rollback() raise ae def updateAllFeeds(self): - FeedUpdater.updateAllFeeds(self.session) + FeedUpdater.updateAllFeeds(self.preferences(), self.session) self.session.commit() def updateFeed(self, feed, changes):