Mercurial > hg > Feedworm
comparison FeedUpdater.py @ 4:e0199f383442
retrieve a feed for the given URL, store entries as feed_entry rows into the database
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Mon, 26 Apr 2010 19:33:07 +0200 |
parents | |
children | bfd47f55d85b |
comparison
equal
deleted
inserted
replaced
3:2ac144a98370 | 4:e0199f383442 |
---|---|
1 | |
2 from Feed import Feed | |
3 from FeedEntry import FeedEntry | |
4 import feedparser | |
5 | |
6 def updateAllFeeds(session): | |
7 allFeeds = session.query(Feed) | |
8 for feed in allFeeds: | |
9 FeedUpdater(session, feed).update() | |
10 session.commit() | |
11 | |
12 class FeedUpdater(object): | |
13 def __init__(self, session, feed): | |
14 self.session = session | |
15 self.feed = feed | |
16 | |
17 def update(self): | |
18 result = feedparser.parse(self.feed.url) | |
19 for entry in result.entries: | |
20 self.processEntry(entry) | |
21 | |
22 def processEntry(self, entry): | |
23 feedEntry = FeedEntry.findById(entry.id, self.session) | |
24 if feedEntry is None: | |
25 self.createFeedEntry(entry) | |
26 | |
27 def createFeedEntry(self, entry): | |
28 newEntry = FeedEntry(id=entry.id, url=entry.link, title=entry.title, summary=entry.summary) | |
29 newEntry.feed = self.feed | |
30 self.session.add(newEntry) |