create a genericBackend
This commit is contained in:
parent
3bc2312338
commit
c74734545b
6 changed files with 300 additions and 206 deletions
97
weboob/backends/inrocks/GenericBackend.py
Normal file
97
weboob/backends/inrocks/GenericBackend.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2011 Julien Hebert
|
||||
#
|
||||
# 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.
|
||||
|
||||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
|
||||
class GenericNewspaperBackend(BaseBackend, ICapMessages):
|
||||
"GenericNewspaperBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
VERSION = '0.6'
|
||||
LICENSE = 'GPLv3'
|
||||
STORAGE = {'seen': {}}
|
||||
RSS_FEED = None
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
@ -19,13 +19,11 @@
|
|||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
from weboob.capabilities.messages import ICapMessages
|
||||
from .browser import NewspaperInrocksBrowser
|
||||
from .GenericBackend import GenericNewspaperBackend
|
||||
|
||||
class NewspaperInrocksBackend(BaseBackend, ICapMessages):
|
||||
class NewspaperInrocksBackend(GenericNewspaperBackend, ICapMessages):
|
||||
"NewspaperInrocksBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
|
|
@ -37,66 +35,3 @@ class NewspaperInrocksBackend(BaseBackend, ICapMessages):
|
|||
BROWSER = NewspaperInrocksBrowser
|
||||
RSS_FEED = 'http://www.lesinrocks.com/fileadmin/rss/actus.xml'
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
|
|||
97
weboob/backends/lefigaro/GenericBackend.py
Normal file
97
weboob/backends/lefigaro/GenericBackend.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2011 Julien Hebert
|
||||
#
|
||||
# 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.
|
||||
|
||||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
|
||||
class GenericNewspaperBackend(BaseBackend, ICapMessages):
|
||||
"GenericNewspaperBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
VERSION = '0.6'
|
||||
LICENSE = 'GPLv3'
|
||||
STORAGE = {'seen': {}}
|
||||
RSS_FEED = None
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
@ -19,13 +19,11 @@
|
|||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
from weboob.capabilities.messages import ICapMessages
|
||||
from .browser import NewspaperFigaroBrowser
|
||||
from .GenericBackend import GenericNewspaperBackend
|
||||
|
||||
class NewspaperFigaroBackend(BaseBackend, ICapMessages):
|
||||
class NewspaperFigaroBackend(GenericNewspaperBackend, ICapMessages):
|
||||
"NewspaperFigaroBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
|
|
@ -37,66 +35,4 @@ class NewspaperFigaroBackend(BaseBackend, ICapMessages):
|
|||
BROWSER = NewspaperFigaroBrowser
|
||||
RSS_FEED = 'http://rss.lefigaro.fr/lefigaro/laune?format=xml'
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
|
|||
97
weboob/backends/minutes20/GenericBackend.py
Normal file
97
weboob/backends/minutes20/GenericBackend.py
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2011 Julien Hebert
|
||||
#
|
||||
# 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.
|
||||
|
||||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
|
||||
class GenericNewspaperBackend(BaseBackend, ICapMessages):
|
||||
"GenericNewspaperBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
VERSION = '0.6'
|
||||
LICENSE = 'GPLv3'
|
||||
STORAGE = {'seen': {}}
|
||||
RSS_FEED = None
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
@ -16,16 +16,11 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
"backend for http://20minutes.fr"
|
||||
|
||||
# python2.5 compatibility
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages, Message, Thread
|
||||
from weboob.tools.backend import BaseBackend
|
||||
from weboob.tools.newsfeed import Newsfeed
|
||||
from .tools import url2id
|
||||
from weboob.capabilities.messages import ICapMessages
|
||||
from .browser import Newspaper20minutesBrowser
|
||||
from .GenericBackend import GenericNewspaperBackend
|
||||
|
||||
class Newspaper20minutesBackend(BaseBackend, ICapMessages):
|
||||
class Newspaper20minutesBackend(GenericNewspaperBackend, ICapMessages):
|
||||
"Newspaper20minutesBackend class"
|
||||
MAINTAINER = 'Julien Hebert'
|
||||
EMAIL = 'juke@free.fr'
|
||||
|
|
@ -37,66 +32,3 @@ class Newspaper20minutesBackend(BaseBackend, ICapMessages):
|
|||
BROWSER = Newspaper20minutesBrowser
|
||||
RSS_FEED = 'http://www.20minutes.fr/rss/20minutes.xml'
|
||||
|
||||
def get_thread(self, _id):
|
||||
if isinstance(_id, Thread):
|
||||
thread = _id
|
||||
_id = thread.id
|
||||
else:
|
||||
thread = None
|
||||
|
||||
with self.browser:
|
||||
content = self.browser.get_content(_id)
|
||||
|
||||
if not thread:
|
||||
thread = Thread(_id)
|
||||
|
||||
flags = Message.IS_HTML
|
||||
if not thread.id in self.storage.get('seen', default={}):
|
||||
flags |= Message.IS_UNREAD
|
||||
thread.title = content.title
|
||||
if not thread.date:
|
||||
thread.date = content.date
|
||||
|
||||
thread.root = Message(
|
||||
thread=thread,
|
||||
id=0,
|
||||
title=content.title,
|
||||
sender=content.author,
|
||||
receivers=None,
|
||||
date=thread.date,
|
||||
parent=None,
|
||||
content=content.body,
|
||||
signature='URL: %s' % content.url,
|
||||
flags=flags,
|
||||
children= [])
|
||||
return thread
|
||||
|
||||
def iter_threads(self):
|
||||
for article in Newsfeed(self.RSS_FEED, url2id).iter_entries():
|
||||
thread = Thread(article.id)
|
||||
thread.title = article.title
|
||||
thread.date = article.datetime
|
||||
yield(thread)
|
||||
|
||||
def fill_thread(self, thread):
|
||||
"fill the thread"
|
||||
return self.get_thread(thread)
|
||||
|
||||
def iter_unread_messages(self, thread=None):
|
||||
for thread in self.iter_threads():
|
||||
self.fill_thread(thread)
|
||||
for msg in thread.iter_all_messages():
|
||||
if msg.flags & msg.IS_UNREAD:
|
||||
yield msg
|
||||
|
||||
def set_message_read(self, message):
|
||||
self.storage.set(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
self.storage.get(
|
||||
'seen',
|
||||
message.thread.id,
|
||||
'comments',
|
||||
default=[]) + [message.id])
|
||||
self.storage.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue