Mercurial > hg > Feedworm
view feedupdate-main.py @ 112:e4038dd8cc0e
add a comment about a Feedparser bug wrt python3
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 31 Mar 2011 03:50:46 +0200 |
parents | 43c234c8fe87 |
children | 32a173cb081c |
line wrap: on
line source
#!/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 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()