Mercurial > hg > Feedworm
comparison 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 |
comparison
equal
deleted
inserted
replaced
67:c3f2b11e7420 | 68:525a52169f60 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 import Database | 3 import Database |
4 from datetime import datetime, timedelta | |
4 from Feed import Feed | 5 from Feed import Feed |
5 import FeedUpdater | 6 import FeedUpdater |
6 import logging | 7 import logging |
8 import Mapping | |
9 from sqlalchemy.sql import and_ | |
7 import util | 10 import util |
8 | 11 |
9 logger = logging.getLogger("feedupdater") | 12 logger = logging.getLogger("feedupdater") |
10 | 13 |
11 def listFeeds(session): | 14 def listFeeds(session): |
13 for feed in allFeeds: | 16 for feed in allFeeds: |
14 logger.info("feed: " + feed.name) | 17 logger.info("feed: " + feed.name) |
15 for entry in feed.entries: | 18 for entry in feed.entries: |
16 print entry.title | 19 print entry.title |
17 | 20 |
21 def expireFeedEntries(session): | |
22 expireDate = _calculateExpireDate() | |
23 logger.info("expiring entries older than " + str(expireDate)) | |
24 feedEntry = Mapping.feedEntryTable | |
25 deleteStatement = feedEntry.delete().where( | |
26 and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1) | |
27 ) | |
28 deleteStatement.execute() | |
29 | |
30 def _calculateExpireDate(): | |
31 now = datetime.now() | |
32 delta = timedelta(days=30) | |
33 return now - delta | |
34 | |
18 if __name__ == "__main__": | 35 if __name__ == "__main__": |
19 util.configureLogging() | 36 util.configureLogging() |
20 session = Database.createSession() | 37 session = Database.createSession() |
21 | 38 |
22 #util.loadFeeds(session) | 39 #util.loadFeeds(session) |
23 #util.forceUpdateAllFeeds(session) | 40 #util.forceUpdateAllFeeds(session) |
24 #listFeeds(session) | 41 #listFeeds(session) |
25 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") | 42 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") |
26 FeedUpdater.updateAllFeeds(session) | 43 # FeedUpdater.updateAllFeeds(session) |
44 expireFeedEntries(session) | |
27 | 45 |
28 session.close() | 46 session.close() |