WIP: updatable
This commit is contained in:
parent
8e394c2203
commit
b08db0035e
4 changed files with 52 additions and 6 deletions
|
|
@ -20,9 +20,10 @@ 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
|
||||
|
||||
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
|
||||
class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
|
||||
MAINTAINER = 'Romain Bignon'
|
||||
EMAIL = 'romain@peerfuse.org'
|
||||
VERSION = '1.0'
|
||||
|
|
@ -30,7 +31,7 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
|
|||
def __init__(self, weboob):
|
||||
Backend.__init__(self, weboob)
|
||||
|
||||
def iter_new_messages(self, thread=None):
|
||||
def iter_messages(self):
|
||||
articles_list = ArticlesList('newspaper')
|
||||
for article in articles_list.iter_articles():
|
||||
yield Message('threadid', article._id, article.title, article.author, signature='Bite bite bite bite',
|
||||
|
|
|
|||
|
|
@ -78,12 +78,11 @@ class Message:
|
|||
return result.encode('utf-8')
|
||||
|
||||
class ICapMessages:
|
||||
def iter_new_messages(self, thread=None):
|
||||
def iter_messages(self):
|
||||
"""
|
||||
Iterates on new messages from last time this function has been called.
|
||||
|
||||
@param thread [str] if given, get new messages for a specific thread.
|
||||
@return [list] a list of Message objects.
|
||||
@return [list] Message objects
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
|
|||
46
weboob/capabilities/updatable.py
Normal file
46
weboob/capabilities/updatable.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# -*- 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.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class ICapUpdatable:
|
||||
snapshots = {}
|
||||
|
||||
def take_snapshot(self, name, collection):
|
||||
if name not in self.snapshots:
|
||||
self.snapshots[name] = dict(original=set(collection))
|
||||
elif 'original' in self.snapshots[name]:
|
||||
if 'updated' in self.snapshots[name]:
|
||||
self.snapshots[name]['original'] = self.snapshots[name]['updated']
|
||||
self.snapshots[name]['updated'] = set(collection)
|
||||
|
||||
def iter_new_items(self, name):
|
||||
"""
|
||||
Iterates on new items from last time this function has been called.
|
||||
|
||||
@param name [str] name of the collection to iter
|
||||
@return [iter] new items
|
||||
"""
|
||||
if name not in self.snapshots:
|
||||
raise ValueError('"%s" has not been snapshot previously' % name)
|
||||
elif 'original' not in self.snapshots[name] or 'updated' not in self.snapshots[name]:
|
||||
raise ValueError('At least two snapshots are required to detect new items')
|
||||
diff = self.snapshots[name]['updated'] - self.snapshots[name]['original']
|
||||
for item in diff:
|
||||
yield item
|
||||
|
|
@ -35,7 +35,7 @@ class Application(BaseApplication):
|
|||
print '= Processing backend name = %s' % name
|
||||
if backend.has_caps(ICapMessages):
|
||||
print '== Backend is ICapMessages => print its messages'
|
||||
for message in backend.iter_new_messages():
|
||||
for message in backend.iter_messages():
|
||||
print '=== %s' % message
|
||||
if backend.has_caps(ICapMessagesReply):
|
||||
print '== Backend is ICapMessagesReply => TODO'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue