iter_new_messages() return correctly every articles and comments

This commit is contained in:
Romain Bignon 2010-04-04 14:37:54 +02:00
commit 538b810d06
3 changed files with 24 additions and 6 deletions

View file

@ -21,7 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.backend import Backend
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply, Message
from weboob.capabilities.updatable import ICapUpdatable
from feeds import ArticlesList
from .feeds import ArticlesList
from .browser import DLFP
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
NAME = 'dlfp'
@ -32,9 +34,25 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
CONFIG = {'username': Backend.ConfigField(description='Username on website'),
'password': Backend.ConfigField(description='Password of account', is_masked=True)
}
browser = None
def need_browser(func):
def inner(self, *args, **kwargs):
if not self.browser:
self.browser = DLFP(self.config['username'], self.config['password'])
return func(self, *args, **kwargs)
return inner
@need_browser
def iter_messages(self):
articles_list = ArticlesList('newspaper')
for article in articles_list.iter_articles():
yield Message('threadid', article.id, article.title, article.author, article.datetime, signature='Bite bite bite bite',
content='Content content\nContent content.')
print article.id
thread = self.browser.get_content(article.id)
yield Message(thread.id, 0, thread.title, thread.author, article.datetime, signature='URL: %s' % article.url, content=''.join([thread.body, thread.part2]))
for comment in thread.iter_all_comments():
yield Message(thread.id, comment.id, comment.title, comment.author, comment.date, comment.reply_id, comment.body)
def iter_new_messages(self):
return self.iter_messages()

View file

@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.tools.browser import Browser
from .pages.index import IndexPage, LoginPage
from .pages.news import ContentPage
from .tools import id2url
class DLFP(Browser):
DOMAIN = 'linuxfr.org'
@ -36,7 +37,8 @@ class DLFP(Browser):
return self.location('https://linuxfr.org')
def get_content(self, _id):
pass
self.location(id2url(_id))
return self.page.get_article()
def login(self):
self.location('/login.html', 'login=%s&passwd=%s&isauto=1' % (self.username, self.password))

View file

@ -18,9 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from logging import warning
import feedparser
import re
from datetime import datetime
from .tools import url2id