weboob-devel/weboob/backends/dlfp/backend.py

58 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""
Copyright(C) 2010 Romain Bignon
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
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 .browser import DLFP
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
NAME = 'dlfp'
MAINTAINER = 'Romain Bignon'
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)
}
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():
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()