Mercurial > hg > Feedworm
annotate util.py @ 45:0604e374c1d6
pass session when creating a new feed
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 14 May 2010 15:24:51 +0200 |
parents | 12ed8b5fa08c |
children | 03358c113170 |
rev | line source |
---|---|
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
1 |
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
|
2 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
|
3 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
|
4 import logging |
12
9ede118b93ef
move session creation into its own module
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
5 |
13
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
6 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
|
7 |
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
8 def configureLogging(): |
591ecc2a99bd
move logging configuration to the util module, configure logging for sqlalchemy
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
12
diff
changeset
|
9 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
|
10 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
|
11 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
|
12 |
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
|
13 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
|
14 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
|
15 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
|
16 (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
|
17 # 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
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 |
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
|
24 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
|
25 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
|
26 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
|
27 session.commit() |
43
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
28 |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
29 def str2bool(string): |
12ed8b5fa08c
first system preference: configure app to stat maximized.
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
37
diff
changeset
|
30 return string.lower() in ["yes", "true", "t", "1"] |