Mercurial > hg > Feedworm
comparison feedupdate-main.py @ 110:43c234c8fe87
store the number of days to keep feed entries as preference setting in the database. The feed update process reads and uses that value.
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Wed, 30 Mar 2011 02:59:22 +0200 |
parents | bf22b32ae9f7 |
children | 32a173cb081c |
comparison
equal
deleted
inserted
replaced
109:bf22b32ae9f7 | 110:43c234c8fe87 |
---|---|
4 from datetime import datetime, timedelta | 4 from datetime import datetime, timedelta |
5 from Feed import Feed | 5 from Feed import Feed |
6 import FeedUpdater | 6 import FeedUpdater |
7 import logging | 7 import logging |
8 import Mapping | 8 import Mapping |
9 from Preferences import Preferences | |
9 from sqlalchemy.sql import and_ | 10 from sqlalchemy.sql import and_ |
10 import util | 11 import util |
11 | 12 |
12 logger = logging.getLogger("feedupdater") | 13 logger = logging.getLogger("feedupdater") |
13 | 14 |
17 logger.info("feed: " + feed.name) | 18 logger.info("feed: " + feed.name) |
18 for entry in feed.entries: | 19 for entry in feed.entries: |
19 print entry.title | 20 print entry.title |
20 | 21 |
21 def expireFeedEntries(session): | 22 def expireFeedEntries(session): |
22 expireDate = _calculateExpireDate() | 23 expireDate = _calculateExpireDate(session) |
23 logger.info("expiring entries older than " + str(expireDate)) | 24 logger.info("expiring entries older than " + str(expireDate)) |
24 feedEntry = Mapping.feedEntryTable | 25 feedEntry = Mapping.feedEntryTable |
25 deleteStatement = feedEntry.delete().where( | 26 deleteStatement = feedEntry.delete().where( |
26 and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1) | 27 and_(feedEntry.c.create_timestamp < expireDate, feedEntry.c.read == 1) |
27 ) | 28 ) |
28 deleteStatement.execute() | 29 deleteStatement.execute() |
29 | 30 |
30 def _calculateExpireDate(): | 31 def _calculateExpireDate(session): |
31 now = datetime.now() | 32 now = datetime.now() |
32 delta = timedelta(days=90) | 33 daysToKeepFeedEntries = Preferences(session).daysToKeepFeedEntries() |
34 delta = timedelta(days=daysToKeepFeedEntries) | |
33 return now - delta | 35 return now - delta |
34 | 36 |
35 if __name__ == "__main__": | 37 if __name__ == "__main__": |
36 util.configureLogging() | 38 util.configureLogging() |
37 session = Database.createSession() | 39 session = Database.createSession() |
38 | 40 |
39 #util.loadFeeds(session) | 41 #util.loadFeeds(session) |
40 #util.forceUpdateAllFeeds(session) | 42 #util.forceUpdateAllFeeds(session) |
41 #listFeeds(session) | 43 #listFeeds(session) |
42 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") | 44 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") |
43 FeedUpdater.updateAllFeeds(session) | 45 FeedUpdater.updateAllFeeds(session) |
44 expireFeedEntries(session) | 46 expireFeedEntries(session) |
45 | 47 |
46 session.close() | 48 session.close() |