can fetch also telegrams
This commit is contained in:
parent
140024b813
commit
e66f47e3fb
3 changed files with 32 additions and 14 deletions
|
|
@ -32,7 +32,9 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
LICENSE = 'GPLv3'
|
LICENSE = 'GPLv3'
|
||||||
CONFIG = {'username': Backend.ConfigField(description='Username on website'),
|
CONFIG = {'username': Backend.ConfigField(description='Username on website'),
|
||||||
'password': Backend.ConfigField(description='Password of account', is_masked=True)
|
'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
|
browser = None
|
||||||
|
|
||||||
|
|
@ -46,9 +48,15 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
|
||||||
|
|
||||||
@need_browser
|
@need_browser
|
||||||
def iter_messages(self):
|
def iter_messages(self):
|
||||||
articles_list = ArticlesList('newspaper')
|
if self.config['get_news']:
|
||||||
for article in articles_list.iter_articles():
|
for message in self._iter_messages('newspaper'):
|
||||||
print article.id
|
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)
|
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]))
|
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():
|
for comment in thread.iter_all_comments():
|
||||||
|
|
|
||||||
|
|
@ -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.tools.browser import BrowserIncorrectPassword, BasePage
|
||||||
from weboob.capabilities.messages import Message
|
|
||||||
|
|
||||||
class DLFPPage(BasePage):
|
class DLFPPage(BasePage):
|
||||||
def is_logged(self):
|
def is_logged(self):
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,12 @@ class Article(object):
|
||||||
for a in div.find('h1').getiterator('a'):
|
for a in div.find('h1').getiterator('a'):
|
||||||
if a.text: self.title += a.text
|
if a.text: self.title += a.text
|
||||||
if a.tail: self.title += a.tail
|
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 '):
|
if div.attrib.get('class', '').startswith('bodydiv '):
|
||||||
self.body = tostring(div)
|
self.body = tostring(div)
|
||||||
|
|
||||||
|
|
@ -99,7 +104,13 @@ class ContentPage(DLFPPage):
|
||||||
def loaded(self):
|
def loaded(self):
|
||||||
self.article = None
|
self.article = None
|
||||||
for div in self.document.find('body').find('div').findall('div'):
|
for div in self.document.find('body').find('div').findall('div'):
|
||||||
if div.attrib.get('class', '') == 'newsdiv':
|
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)
|
self.article = Article(url2id(self.url), div)
|
||||||
if div.attrib.get('class', '') == 'articlediv':
|
if div.attrib.get('class', '') == 'articlediv':
|
||||||
self.article.parse_part2(div)
|
self.article.parse_part2(div)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue