backend newsfeed version is 0.3 (conforming to weboob version)

This commit is contained in:
Romain Bignon 2010-10-16 18:58:54 +02:00
commit fe39601810
3 changed files with 15 additions and 19 deletions

View file

@ -44,7 +44,7 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost):
BROWSER = DLFP BROWSER = DLFP
RSS_TELEGRAMS= "https://linuxfr.org/backend/journaux/rss20.rss" RSS_TELEGRAMS= "https://linuxfr.org/backend/journaux/rss20.rss"
RSS_NEWSPAPERS = "https://linuxfr.org/backend/news/rss20.rss" RSS_NEWSPAPERS = "https://linuxfr.org/backend/news/rss20.rss"
def create_default_browser(self): def create_default_browser(self):
return self.create_browser(self.config['username'], self.config['password']) return self.create_browser(self.config['username'], self.config['password'])
@ -55,7 +55,7 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost):
whats.add(self.RSS_NEWSPAPERS) whats.add(self.RSS_NEWSPAPERS)
if self.config['get_telegrams']: if self.config['get_telegrams']:
whats.add(self.RSS_TELEGRAMS) whats.add(self.RSS_TELEGRAMS)
for what in whats: for what in whats:
for article in Newsfeed(what, url2id).iter_entries(): for article in Newsfeed(what, url2id).iter_entries():

View file

@ -18,29 +18,29 @@
from weboob.tools.backend import BaseBackend from weboob.tools.backend import BaseBackend
from weboob.capabilities.messages import ICapMessages, Message, Thread from weboob.capabilities.messages import ICapMessages, Message, Thread
from weboob.tools.newsfeed import Newsfeed from weboob.tools.newsfeed import Newsfeed
class NewsfeedBackend(BaseBackend, ICapMessages): class NewsfeedBackend(BaseBackend, ICapMessages):
NAME = 'newsfeed' NAME = 'newsfeed'
MAINTAINER = u"Clément Schreiner" MAINTAINER = u"Clément Schreiner"
EMAIL = "clemux@clemux.info" EMAIL = "clemux@clemux.info"
VERSION = "0.1" VERSION = "0.3"
DESCRIPTION = "Loads RSS and Atom feeds from any websites" DESCRIPTION = "Loads RSS and Atom feeds from any websites"
LICENSE = "GPLv3" LICENSE = "GPLv3"
CONFIG = {'url': BaseBackend.ConfigField(description="Atom/RSS feed's url"),} CONFIG = {'url': BaseBackend.ConfigField(description="Atom/RSS feed's url"),}
STORAGE = {'seen': []} STORAGE = {'seen': []}
def iter_threads(self): def iter_threads(self):
for article in Newsfeed(self.config["url"]).iter_entries(): for article in Newsfeed(self.config["url"]).iter_entries():
thread = Thread(article.id) thread = Thread(article.id)
thread.title = article.title thread.title = article.title
yield thread yield thread
def get_thread(self, id): def get_thread(self, id):
if isinstance(id, Thread): if isinstance(id, Thread):
@ -68,8 +68,8 @@ class NewsfeedBackend(BaseBackend, ICapMessages):
children=[], children=[],
flags=flags) flags=flags)
return thread return thread
def iter_unread_messages(self, thread=None): def iter_unread_messages(self, thread=None):
for thread in self.iter_threads(): for thread in self.iter_threads():

View file

@ -19,6 +19,9 @@ import datetime
import feedparser import feedparser
__all__ = ['Entry', 'Newsfeed']
class Entry: class Entry:
def __init__(self, entry, url2id=None): def __init__(self, entry, url2id=None):
if url2id: if url2id:
@ -50,7 +53,7 @@ class Entry:
self.summary = entry["summary"] self.summary = entry["summary"]
else: else:
self.summary = None self.summary = None
self.content = [] self.content = []
if entry.has_key("content"): if entry.has_key("content"):
for i in entry["content"]: for i in entry["content"]:
@ -59,18 +62,12 @@ class Entry:
self.content.append(self.summary) self.content.append(self.summary)
else: else:
self.content = None self.content = None
class Newsfeed: class Newsfeed:
def __init__(self, url, url2id=None): def __init__(self, url, url2id=None):
self.feed = feedparser.parse(url) self.feed = feedparser.parse(url)
self.url2id = url2id self.url2id = url2id
def iter_entries(self): def iter_entries(self):
for entry in self.feed['entries']: for entry in self.feed['entries']:
yield Entry(entry, self.url2id) yield Entry(entry, self.url2id)
@ -79,4 +76,3 @@ class Newsfeed:
for entry in self.feed['entries']: for entry in self.feed['entries']:
if entry.id == id: if entry.id == id:
return Entry(entry, self.url2id) return Entry(entry, self.url2id)