Get comments only in case of rss-comments changes

This commit is contained in:
Florent 2012-03-06 15:49:29 +01:00 committed by Romain Bignon
commit d12877fe55
3 changed files with 21 additions and 2 deletions

View file

@ -86,6 +86,7 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapContent):
continue continue
thread = Thread(article.id) thread = Thread(article.id)
thread.title = article.title thread.title = article.title
thread._rsscomment = article.rsscomment
if article.datetime: if article.datetime:
thread.date = article.datetime thread.date = article.datetime
yield thread yield thread
@ -97,6 +98,12 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapContent):
else: else:
thread = None thread = None
oldhash = self.storage.get('hash', id, default="")
newhash = self.browser.get_hash(thread._rsscomment)
if not getseen and oldhash == newhash:
return None
self.storage.set('hash', id, newhash)
self.storage.save()
with self.browser: with self.browser:
content = self.browser.get_content(id) content = self.browser.get_content(id)
@ -138,7 +145,7 @@ class DLFPBackend(BaseBackend, ICapMessages, ICapMessagesPost, ICapContent):
flags = Message.IS_HTML flags = Message.IS_HTML
if not com.id in self.storage.get('seen', parent.thread.id, 'comments', default=[]): if not com.id in self.storage.get('seen', parent.thread.id, 'comments', default=[]):
flags |= Message.IS_UNREAD flags |= Message.IS_UNREAD
if getseen or flags & Message.IS_UNREAD: if getseen or flags & Message.IS_UNREAD:
com.parse() com.parse()
message = Message(thread=parent.thread, message = Message(thread=parent.thread,

View file

@ -20,12 +20,14 @@
import urllib import urllib
import re import re
import hashlib
import lxml
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound, BrowserHTTPError, BrowserIncorrectPassword, BrokenPageError from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound, BrowserHTTPError, BrowserIncorrectPassword, BrokenPageError
from weboob.capabilities.messages import CantSendMessage from weboob.capabilities.messages import CantSendMessage
from .pages.index import IndexPage, LoginPage from .pages.index import IndexPage, LoginPage
from .pages.news import ContentPage, NewCommentPage, NodePage, CommentPage, NewTagPage from .pages.news import ContentPage, NewCommentPage, NodePage, CommentPage, NewTagPage, RSSComment
from .pages.board import BoardIndexPage from .pages.board import BoardIndexPage
from .pages.wiki import WikiEditPage from .pages.wiki import WikiEditPage
from .tools import id2url, url2id from .tools import id2url, url2id
@ -50,6 +52,7 @@ class DLFP(BaseBrowser):
'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments': NodePage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments': NodePage,
'https?://[^/]*linuxfr\.org/nodes/(\d+)/tags/nouveau': NewTagPage, 'https?://[^/]*linuxfr\.org/nodes/(\d+)/tags/nouveau': NewTagPage,
'https?://[^/]*linuxfr\.org/board/index.xml': BoardIndexPage, 'https?://[^/]*linuxfr\.org/board/index.xml': BoardIndexPage,
'https?://[^/]*linuxfr\.org/nodes/(\d+)/comments.atom': RSSComment,
} }
last_board_msg_id = None last_board_msg_id = None
@ -128,6 +131,11 @@ class DLFP(BaseBrowser):
elif self.is_on_page(ContentPage): elif self.is_on_page(ContentPage):
return self.page.get_article().body return self.page.get_article().body
def get_hash(self, url):
self.location(url)
myhash = hashlib.md5(lxml.etree.tostring(self.page.document)).hexdigest()
return myhash
def get_content(self, _id): def get_content(self, _id):
url, _id = self.parse_id(_id) url, _id = self.parse_id(_id)

View file

@ -26,6 +26,10 @@ from ..tools import url2id
from .index import DLFPPage from .index import DLFPPage
class RSSComment(DLFPPage):
def on_loaded(self):
pass
class Content(object): class Content(object):
TAGGABLE = False TAGGABLE = False