comparison feedupdate-main.py @ 108:e50d446f9942 python3

updates fro python3
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 29 Mar 2011 03:17:30 +0200
parents d20e99d46d78
children
comparison
equal deleted inserted replaced
107:863599e84269 108:e50d446f9942
1 #!/usr/bin/env python 1 #!/usr/bin/env python3
2 2
3 import Database 3 import Database
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 sqlalchemy.sql import and_ 9 from sqlalchemy.sql import and_
10 import sys
10 import util 11 import util
11 12
12 logger = logging.getLogger("feedupdater") 13 logger = logging.getLogger("feedupdater")
13 14
14 def listFeeds(session): 15 def listFeeds(session):
15 allFeeds = session.query(Feed) 16 allFeeds = session.query(Feed)
16 for feed in allFeeds: 17 for feed in allFeeds:
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()
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
30 def _calculateExpireDate(): 31 def _calculateExpireDate():
31 now = datetime.now() 32 now = datetime.now()
32 delta = timedelta(days=30) 33 delta = timedelta(days=30)
33 return now - delta 34 return now - delta
34 35
36 def checkPythonVersion():
37 version = sys.version_info
38 if version[0] < 3:
39 print("feedupdate-main must run on Python 3")
40 sys.exit(1)
41
35 if __name__ == "__main__": 42 if __name__ == "__main__":
43 checkPythonVersion()
36 util.configureLogging() 44 util.configureLogging()
37 session = Database.createSession() 45 session = Database.createSession()
38 46
39 #util.loadFeeds(session) 47 #util.loadFeeds(session)
40 #util.forceUpdateAllFeeds(session) 48 #util.forceUpdateAllFeeds(session)
41 #listFeeds(session) 49 #listFeeds(session)
42 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml") 50 #OpmlImport.createFeedsFromOPML(session, "feed-data/feeds.opml.xml")
43 FeedUpdater.updateAllFeeds(session) 51 FeedUpdater.updateAllFeeds(session)
44 expireFeedEntries(session) 52 expireFeedEntries(session)
45 53
46 session.close() 54 session.close()