comparison backend/sqlalchemy/FeedUpdater.py @ 123:862760b161b4 backend

restructured adding a feed so that only the URL is passed into the backend - the rest of the operation is backend-internal
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 22 Aug 2011 10:30:33 +0200
parents 510a5d00e98a
children 6ea813cfac33
comparison
equal deleted inserted replaced
122:f5afe0c1f4d2 123:862760b161b4
31 if hasattr(entry, "content"): 31 if hasattr(entry, "content"):
32 entry.summary = entry.content[0].value 32 entry.summary = entry.content[0].value
33 else: 33 else:
34 entry.summary = "" 34 entry.summary = ""
35 35
36 def createNewFeed(url, session):
37 # when updating to python3 see http://code.google.com/p/feedparser/issues/detail?id=260
38 result = feedparser.parse(url)
39 if result.has_key("title"):
40 title = result["feed"].title
41 else:
42 title = url
43 newFeed = Feed(title, url)
44 session.add(newFeed)
45
46 FeedUpdater(session, newFeed).update()
47
48
36 class FeedUpdater(object): 49 class FeedUpdater(object):
37 def __init__(self, session, feed): 50 def __init__(self, session, feed):
38 self.session = session 51 self.session = session
39 self.feed = feed 52 self.feed = feed
40
41 # TODO this is a HACK! creating new instances from itself is bad but required due to the storage of the session.
42 def createNewFeed(self, url):
43 # when updating to python3 see http://code.google.com/p/feedparser/issues/detail?id=260
44 result = feedparser.parse(url)
45 if result.has_key("title"):
46 title = result["feed"].title
47 else:
48 title = url
49 newFeed = Feed(title, url)
50 self.session.add(newFeed)
51
52 FeedUpdater(self.session, newFeed).update()
53 53
54 def update(self): 54 def update(self):
55 log.info("updating " + self.feed.rss_url) 55 log.info("updating " + self.feed.rss_url)
56 result = self.getFeed() 56 result = self.getFeed()
57 for entry in result.entries: 57 for entry in result.entries: