Commit 6e3e93e0 authored by Romain Bignon's avatar Romain Bignon

use storage to store dlfp messages state

parent e883c355
......@@ -71,7 +71,7 @@ class Backend(object):
self.config[name] = value
self.storage = storage
if self.storage:
self.storage.load(self.name, self.CONFIG)
self.storage.load(self.name, self.STORAGE)
def has_caps(self, *caps):
for c in caps:
......
......@@ -38,6 +38,7 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
'get_news': Backend.ConfigField(default=True, description='Get newspapers'),
'get_telegrams': Backend.ConfigField(default=False, description='Get telegrams'),
}
STORAGE = {'seen': {'contents': [], 'comments': []}}
browser = None
def need_browser(func):
......@@ -60,22 +61,27 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
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,
content=''.join([thread.body, thread.part2]),
signature='URL: %s' % article.url)
for comment in thread.iter_all_comments():
if not thread.id in self.storage.get(self.name, 'seen', 'contents'):
self.storage.get(self.name, 'seen', 'contents').append(thread.id)
yield Message(thread.id,
comment.id,
comment.title,
comment.author,
comment.date,
comment.reply_id,
comment.body,
'Score: %d' % comment.score)
0,
thread.title,
thread.author,
article.datetime,
content=''.join([thread.body, thread.part2]),
signature='URL: %s' % article.url)
for comment in thread.iter_all_comments():
if not comment.id in self.storage.get(self.name, 'seen', 'comments'):
self.storage.get(self.name, 'seen', 'comments').append(comment.id)
yield Message(thread.id,
comment.id,
comment.title,
comment.author,
comment.date,
comment.reply_id,
comment.body,
'Score: %d' % comment.score)
self.storage.save(self.name)
def iter_new_messages(self):
return self.iter_messages()
......@@ -79,6 +79,7 @@ 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
self.title = self.title.strip()
subdivs = div.findall('a')
if len(subdivs) > 1:
date_s = unicode(subdivs[1].text)
......
......@@ -48,11 +48,11 @@ else:
self.config.values[backend] = default.copy()
self.config.values[backend].update(d)
def save(self):
def save(self, backend):
self.config.save()
def set(self, backend, *args):
self.config.set(backend, self.backends[backend])
self.config.set(backend, *args)
def get(self, backend, *args, **kwargs):
return self.config.get(backend, *args, **kwargs)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment