can fetch also telegrams

This commit is contained in:
Romain Bignon 2010-04-04 18:15:07 +02:00
commit e66f47e3fb
3 changed files with 32 additions and 14 deletions

View file

@ -31,8 +31,10 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
EMAIL = 'romain@peerfuse.org'
VERSION = '1.0'
LICENSE = 'GPLv3'
CONFIG = {'username': Backend.ConfigField(description='Username on website'),
'password': Backend.ConfigField(description='Password of account', is_masked=True)
CONFIG = {'username': Backend.ConfigField(description='Username on website'),
'password': Backend.ConfigField(description='Password of account', is_masked=True),
'get_news': Backend.ConfigField(default=True, description='Get newspapers'),
'get_telegrams': Backend.ConfigField(default=False, description='Get telegrams'),
}
browser = None
@ -46,9 +48,15 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
@need_browser
def iter_messages(self):
articles_list = ArticlesList('newspaper')
for article in articles_list.iter_articles():
print article.id
if self.config['get_news']:
for message in self._iter_messages('newspaper'):
yield message
if self.config['get_telegrams']:
for message in self._iter_messages('telegram'):
yield message
def _iter_messages(self, what):
for article in ArticlesList(what).iter_articles():
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():

View file

@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""
from weboob.tools.browser import BrowserIncorrectPassword, BasePage
from weboob.capabilities.messages import Message
class DLFPPage(BasePage):
def is_logged(self):

View file

@ -79,7 +79,12 @@ class Article(object):
for a in div.find('h1').getiterator('a'):
if a.text: self.title += a.text
if a.tail: self.title += a.tail
date_s = unicode(div.findall('a')[1].text)
subdivs = div.findall('a')
if len(subdivs) > 1:
date_s = unicode(subdivs[1].text)
else:
date_s = unicode(div.find('i').tail)
print date_s
if div.attrib.get('class', '').startswith('bodydiv '):
self.body = tostring(div)
@ -99,13 +104,19 @@ class ContentPage(DLFPPage):
def loaded(self):
self.article = None
for div in self.document.find('body').find('div').findall('div'):
if div.attrib.get('class', '') == 'newsdiv':
self.article = Article(url2id(self.url), div)
if div.attrib.get('class', '') == 'articlediv':
self.article.parse_part2(div)
if div.attrib.get('class', '') == 'comments':
comment = Comment(div, 0)
self.article.append_comment(comment)
self.parse_div(div)
if div.attrib.get('class', '') == 'centraldiv':
for subdiv in div.findall('div'):
self.parse_div(subdiv)
def parse_div(self, div):
if div.attrib.get('class', '') in ('newsdiv', 'centraldiv'):
self.article = Article(url2id(self.url), div)
if div.attrib.get('class', '') == 'articlediv':
self.article.parse_part2(div)
if div.attrib.get('class', '') == 'comments':
comment = Comment(div, 0)
self.article.append_comment(comment)
def get_article(self):
return self.article