Mercurial > hg > Feedworm
changeset 161:2940e74c9663
Creating a feed via the GUI works now.
author | dirk |
---|---|
date | Mon, 29 Aug 2011 03:08:05 +0200 |
parents | 86f828096aaf |
children | ab2b26412b77 |
files | backend/couchdb/CouchDbBackend.py backend/couchdb/Feed.py backend/couchdb/FeedUpdater.py |
diffstat | 3 files changed, 21 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/couchdb/CouchDbBackend.py Mon Aug 29 03:07:50 2011 +0200 +++ b/backend/couchdb/CouchDbBackend.py Mon Aug 29 03:08:05 2011 +0200 @@ -67,7 +67,7 @@ raise Exception("not yet implemented") def createFeed(self, url): - raise Exception("not yet implemented") + FeedUpdater.createFeed(url, self.database) def updateFeed(self, feed, changes): raise Exception("not yet implemented")
--- a/backend/couchdb/Feed.py Mon Aug 29 03:07:50 2011 +0200 +++ b/backend/couchdb/Feed.py Mon Aug 29 03:08:05 2011 +0200 @@ -15,6 +15,13 @@ def all(database): return Feed.view(database, "feedtest/feeds") + @staticmethod + def create(url, title): + feed = Feed() + feed.rss_url = url + feed.title = title + return feed + def needsUpdate(self): delta = datetime.now() - self.next_update return delta.total_seconds() > self._updateIntervalInSeconds()
--- a/backend/couchdb/FeedUpdater.py Mon Aug 29 03:07:50 2011 +0200 +++ b/backend/couchdb/FeedUpdater.py Mon Aug 29 03:08:05 2011 +0200 @@ -1,11 +1,24 @@ +from Feed import Feed from FeedEntry import FeedEntry from backend.AbstractFeedUpdater import AbstractFeedUpdater import logging +import feedparser log = logging.getLogger("FeedUpdater") class FeedUpdater(AbstractFeedUpdater): + @staticmethod + def createFeed(url, database): + feedDict = feedparser.parse(url) + if feedDict.has_key("title"): + title = feedDict["feed"].title + else: + title = url + feed = Feed.create(url, title) + feed.store(database) + FeedUpdater(feed, database).update(feedDict) + def __init__(self, feed, database): AbstractFeedUpdater.__init__(self, feed) self.database = database