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