comparison feedupdate-main.py @ 12:9ede118b93ef

move session creation into its own module
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 28 Apr 2010 02:09:48 +0200
parents e87c54b3a216
children 591ecc2a99bd
comparison
equal deleted inserted replaced
11:e87c54b3a216 12:9ede118b93ef
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 from ConfigParser import ConfigParser 3 from database import createSession
4 from Feed import Feed 4 from Feed import Feed
5 from FeedUpdater import updateAllFeeds 5 from FeedUpdater import updateAllFeeds
6 import Mapping
7 import logging 6 import logging
8 import socket
9 from sqlalchemy import create_engine
10 from sqlalchemy.orm import sessionmaker
11 7
12 logger = logging.getLogger("feedupdater") 8 logger = logging.getLogger("feedupdater")
13
14 def loadDatabaseProperties():
15 hostname = socket.gethostname()
16 filename = "database-%s.ini" % hostname
17
18 parser = ConfigParser();
19 parser.read(filename)
20 return parser.get("database", "url")
21 9
22 def createFeed(session): 10 def createFeed(session):
23 if len(session.query(Feed).all()) == 0: 11 if len(session.query(Feed).all()) == 0:
24 newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml") 12 newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml")
25 session.add(newFeed) 13 session.add(newFeed)
31 logger.info("feed: " + feed.name) 19 logger.info("feed: " + feed.name)
32 for entry in feed.entries: 20 for entry in feed.entries:
33 print entry.title 21 print entry.title
34 22
35 if __name__ == "__main__": 23 if __name__ == "__main__":
36 databaseUrl = loadDatabaseProperties() 24 session = createSession()
37 engine = create_engine(databaseUrl,echo=True)
38 Mapping.createMapping(engine)
39 SessionMaker = sessionmaker(bind = engine)
40 session = SessionMaker()
41 25
42 createFeed(session) 26 createFeed(session)
43 updateAllFeeds(session) 27 updateAllFeeds(session)
44 #listFeeds(session) 28 #listFeeds(session)