Mercurial > hg > Feedworm
diff feedupdate-main.py @ 68:525a52169f60
Make FeedEntry table object available in Mapping to use it to expire old, read feed entries.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 10 Aug 2010 03:32:29 +0200 |
parents | d21f5025034d |
children | d20e99d46d78 |
line wrap: on
line diff
--- a/feedupdate-main.py Mon Aug 02 02:43:41 2010 +0200 +++ b/feedupdate-main.py Tue Aug 10 03:32:29 2010 +0200 @@ -1,9 +1,12 @@ #!/usr/bin/env python import Database +from datetime import datetime, timedelta from Feed import Feed import FeedUpdater import logging +import Mapping +from sqlalchemy.sql import and_ import util logger = logging.getLogger("feedupdater") @@ -15,6 +18,20 @@ for entry in feed.entries: print entry.title +def expireFeedEntries(session): + expireDate = _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() + +def _calculateExpireDate(): + now = datetime.now() + delta = timedelta(days=30) + return now - delta + if __name__ == "__main__": util.configureLogging() session = Database.createSession() @@ -23,6 +40,7 @@ #util.forceUpdateAllFeeds(session) #listFeeds(session) #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") - FeedUpdater.updateAllFeeds(session) +# FeedUpdater.updateAllFeeds(session) + expireFeedEntries(session) session.close()