Mercurial > hg > Feedworm
changeset 128:32a173cb081c backend
move updating the feeds to the backend
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 22 Aug 2011 15:04:53 +0200 |
parents | c923e4c57a81 |
children | 5bb58c956e48 |
files | backend/sqlalchemy/SqlAlchemyBackend.py feedupdate-main.py |
diffstat | 2 files changed, 31 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/sqlalchemy/SqlAlchemyBackend.py Mon Aug 22 14:26:54 2011 +0200 +++ b/backend/sqlalchemy/SqlAlchemyBackend.py Mon Aug 22 15:04:53 2011 +0200 @@ -1,8 +1,11 @@ from Preferences import Preferences +from datetime import datetime, timedelta +from sqlalchemy.sql import and_ import Database import FeedList import FeedUpdater +import Mapping import logging import util @@ -61,6 +64,28 @@ entry.markRead() self.session.commit() + def updateAllFeeds(self): + FeedUpdater.updateAllFeeds(self.session) + self.session.commit() + + def expireFeedEntries(self): + logger = logging.getLogger("feedupdater") + expireDate = self._calculateExpireDate() + logger.info("expiring entries older than " + str(expireDate)) + feedEntry = Mapping.feedEntryTable + deleteStatement = feedEntry.delete().where( + and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1) + ) + deleteStatement.execute() + self.session.commit() + + def _calculateExpireDate(self): + now = datetime.now() + daysToKeepFeedEntries = self.prefs.daysToKeepFeedEntries() + delta = timedelta(days=daysToKeepFeedEntries) + return now - delta + def dispose(self): # save all uncommitted state, just in case self.session.commit() + self.session.close()
--- a/feedupdate-main.py Mon Aug 22 14:26:54 2011 +0200 +++ b/feedupdate-main.py Mon Aug 22 15:04:53 2011 +0200 @@ -1,48 +1,11 @@ #!/usr/bin/env python -import Database -from datetime import datetime, timedelta -from Feed import Feed -import FeedUpdater import logging -import Mapping -from Preferences import Preferences -from sqlalchemy.sql import and_ -import util - -logger = logging.getLogger("feedupdater") - -def listFeeds(session): - allFeeds = session.query(Feed) - for feed in allFeeds: - logger.info("feed: " + feed.name) - for entry in feed.entries: - print entry.title - -def expireFeedEntries(session): - expireDate = _calculateExpireDate(session) - logger.info("expiring entries older than " + str(expireDate)) - feedEntry = Mapping.feedEntryTable - deleteStatement = feedEntry.delete().where( - and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1) - ) - deleteStatement.execute() - -def _calculateExpireDate(session): - now = datetime.now() - daysToKeepFeedEntries = Preferences(session).daysToKeepFeedEntries() - delta = timedelta(days=daysToKeepFeedEntries) - return now - delta +from backend.sqlalchemy.SqlAlchemyBackend import SqlAlchemyBackend if __name__ == "__main__": - util.configureLogging() - session = Database.createSession() - - #util.loadFeeds(session) - #util.forceUpdateAllFeeds(session) - #listFeeds(session) - #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") - FeedUpdater.updateAllFeeds(session) - expireFeedEntries(session) - - session.close() + logging.basicConfig(level=logging.DEBUG) + backend = SqlAlchemyBackend() + backend.updateAllFeeds() + backend.expireFeedEntries() + backend.dispose()