use storage to store dlfp messages state
This commit is contained in:
parent
e883c355e5
commit
6e3e93e08b
4 changed files with 25 additions and 18 deletions
|
|
@ -71,7 +71,7 @@ class Backend(object):
|
||||||
self.config[name] = value
|
self.config[name] = value
|
||||||
self.storage = storage
|
self.storage = storage
|
||||||
if self.storage:
|
if self.storage:
|
||||||
self.storage.load(self.name, self.CONFIG)
|
self.storage.load(self.name, self.STORAGE)
|
||||||
|
|
||||||
def has_caps(self, *caps):
|
def has_caps(self, *caps):
|
||||||
for c in 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_news': Backend.ConfigField(default=True, description='Get newspapers'),
|
||||||
'get_telegrams': Backend.ConfigField(default=False, description='Get telegrams'),
|
'get_telegrams': Backend.ConfigField(default=False, description='Get telegrams'),
|
||||||
}
|
}
|
||||||
|
STORAGE = {'seen': {'contents': [], 'comments': []}}
|
||||||
browser = None
|
browser = None
|
||||||
|
|
||||||
def need_browser(func):
|
def need_browser(func):
|
||||||
|
|
@ -60,22 +61,27 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply, ICapUpdatable):
|
||||||
def _iter_messages(self, what):
|
def _iter_messages(self, what):
|
||||||
for article in ArticlesList(what).iter_articles():
|
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,
|
if not thread.id in self.storage.get(self.name, 'seen', 'contents'):
|
||||||
0,
|
self.storage.get(self.name, 'seen', 'contents').append(thread.id)
|
||||||
thread.title,
|
|
||||||
thread.author,
|
|
||||||
article.datetime,
|
|
||||||
content=''.join([thread.body, thread.part2]),
|
|
||||||
signature='URL: %s' % article.url)
|
|
||||||
for comment in thread.iter_all_comments():
|
|
||||||
yield Message(thread.id,
|
yield Message(thread.id,
|
||||||
comment.id,
|
0,
|
||||||
comment.title,
|
thread.title,
|
||||||
comment.author,
|
thread.author,
|
||||||
comment.date,
|
article.datetime,
|
||||||
comment.reply_id,
|
content=''.join([thread.body, thread.part2]),
|
||||||
comment.body,
|
signature='URL: %s' % article.url)
|
||||||
'Score: %d' % comment.score)
|
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):
|
def iter_new_messages(self):
|
||||||
return self.iter_messages()
|
return self.iter_messages()
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ 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
|
||||||
|
self.title = self.title.strip()
|
||||||
subdivs = div.findall('a')
|
subdivs = div.findall('a')
|
||||||
if len(subdivs) > 1:
|
if len(subdivs) > 1:
|
||||||
date_s = unicode(subdivs[1].text)
|
date_s = unicode(subdivs[1].text)
|
||||||
|
|
|
||||||
|
|
@ -48,11 +48,11 @@ else:
|
||||||
self.config.values[backend] = default.copy()
|
self.config.values[backend] = default.copy()
|
||||||
self.config.values[backend].update(d)
|
self.config.values[backend].update(d)
|
||||||
|
|
||||||
def save(self):
|
def save(self, backend):
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
|
||||||
def set(self, backend, *args):
|
def set(self, backend, *args):
|
||||||
self.config.set(backend, self.backends[backend])
|
self.config.set(backend, *args)
|
||||||
|
|
||||||
def get(self, backend, *args, **kwargs):
|
def get(self, backend, *args, **kwargs):
|
||||||
return self.config.get(backend, *args, **kwargs)
|
return self.config.get(backend, *args, **kwargs)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue