comparison util.py @ 119:04a730f9d07d backend

move all sqlalchemy related classes to the respective sub-package. use a backend to abstract from access to the data
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sun, 21 Aug 2011 03:55:16 +0200
parents 254d5b89a6ca
children c923e4c57a81
comparison
equal deleted inserted replaced
118:0e73adb2dec4 119:04a730f9d07d
1 1
2 from Feed import Feed
2 from datetime import datetime, timedelta 3 from datetime import datetime, timedelta
3 from Feed import Feed
4 import logging 4 import logging
5 import sys
6 5
7 logger = logging.getLogger("database") 6 logger = logging.getLogger("database")
8 7
9 def databaseLoggingEnabled(): 8 # TODO remove this
10 loggingEnabled = False 9 #def databaseLoggingEnabled():
11 for arg in sys.argv: 10 # loggingEnabled = False
12 if arg == "--databaseLogging": 11 # for arg in sys.argv:
13 loggingEnabled = True 12 # if arg == "--databaseLogging":
14 return loggingEnabled 13 # loggingEnabled = True
14 # return loggingEnabled
15 15
16 def configureLogging(): 16 # TODO remove this
17 logging.basicConfig(level=logging.DEBUG) 17 #def configureLogging():
18 18 # logging.basicConfig(level=logging.DEBUG)
19 sqlalchemyLogLevel = logging.ERROR 19 #
20 if databaseLoggingEnabled(): 20 # sqlalchemyLogLevel = logging.ERROR
21 sqlalchemyLogLevel = logging.INFO 21 # if databaseLoggingEnabled():
22 logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel) 22 # sqlalchemyLogLevel = logging.INFO
23 23 # logging.getLogger("sqlalchemy").setLevel(sqlalchemyLogLevel)
24 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN) 24 #
25 # logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
25 26
26 def loadFeeds(session=None, filename="feeds.txt"): 27 def loadFeeds(session=None, filename="feeds.txt"):
27 file = open(filename) 28 file = open(filename)
28 for line in file: 29 for line in file:
29 (title, rss_url) = line.split("|") 30 (title, rss_url) = line.split("|")
37 def forceUpdateAllFeeds(session=None): 38 def forceUpdateAllFeeds(session=None):
38 for feed in Feed.all(session): 39 for feed in Feed.all(session):
39 feed.next_update = datetime.now() - timedelta(minutes=1) 40 feed.next_update = datetime.now() - timedelta(minutes=1)
40 session.commit() 41 session.commit()
41 42
42 def str2bool(string):
43 return string.lower() in ["yes", "true", "t", "1"]
44
45 def bool2str(bool):
46 if bool:
47 return "True"
48 else:
49 return "False"