annotate util.py @ 35:aaec263f07ca

Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 05 May 2010 03:07:59 +0200
parents 5813e3c10f14
children 22214d79ed41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 from ConfigParser import ConfigParser
35
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
3 from datetime import datetime, timedelta
34
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
4 from Feed import Feed
13
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
5 import logging
12
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 import socket
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
13
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
8 logger = logging.getLogger("database")
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
9
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
10 def configureLogging():
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
11 logging.basicConfig(level=logging.DEBUG)
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
12 logging.getLogger("sqlalchemy").setLevel(logging.INFO)
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
13 logging.getLogger("sqlalchemy.orm").setLevel(logging.WARN)
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
14
12
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 def loadDatabaseUrl():
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 hostname = socket.gethostname()
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 filename = "database-%s.ini" % hostname
13
591ecc2a99bd move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 12
diff changeset
18 logger.debug("loading database configuration from " + filename)
12
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 parser = ConfigParser();
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 parser.read(filename)
9ede118b93ef move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22 return parser.get("database", "url")
34
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
23
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
24 def loadFeeds(session=None, filename="feeds.txt"):
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
25 file = open(filename)
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
26 for line in file:
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
27 (title, rss_url) = line.split("|")
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
28 # remove the newline
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
29 rss_url = rss_url.rstrip()
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
30 feed = Feed(title, rss_url)
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
31 session.add(feed)
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
32 file.close()
5813e3c10f14 move the database logic out into its own module. Make everything reload safe so that multiple sessions can be created from interactive sessions
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 28
diff changeset
33 session.commit()
35
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
34
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
35 def forceUpdateAllFeeds(session=None):
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
36 for feed in Feed.all(session):
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
37 feed.next_update = datetime.now() - timedelta(minutes=1)
aaec263f07ca Feeds manage the point in time when the next update should happen. FeedUpdater only updates feeds that are due.
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 34
diff changeset
38 session.commit()