From da3ac55fc2abedc7b8864dabe180b0ff6ef5a1a2 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Thu, 5 Mar 2015 07:15:44 +0100 Subject: Take advantage of some new fields of the Feed objects. --- pyaggr3g470r/crawler.py | 7 ++++++- pyaggr3g470r/templates/feed.html | 16 ++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'pyaggr3g470r') diff --git a/pyaggr3g470r/crawler.py b/pyaggr3g470r/crawler.py index 56c3552a..22ed5acc 100644 --- a/pyaggr3g470r/crawler.py +++ b/pyaggr3g470r/crawler.py @@ -55,7 +55,8 @@ def get(*args, **kwargs): response = yield from aiohttp.request('GET', *args, **kwargs) return (yield from response.read_and_close(decode=False)) except Exception as e: - print(e) + #print(e) + feed.last_error = str(e) return None @asyncio.coroutine @@ -69,7 +70,11 @@ def parse_feed(user, feed): data = yield from get(feed.link) if data is None: + feed.error_count += 1 return + feed.error_count = 0 + + feed.last_retrieved = datetime.now() a_feed = feedparser.parse(data) if a_feed['bozo'] == 1: diff --git a/pyaggr3g470r/templates/feed.html b/pyaggr3g470r/templates/feed.html index 09bb54cb..12a7aa50 100644 --- a/pyaggr3g470r/templates/feed.html +++ b/pyaggr3g470r/templates/feed.html @@ -11,17 +11,21 @@

{{ _('This feed contains') }} {{ feed.articles.all()|count }} {{ _('articles') }} {% if nb_articles != 0 %} - ({{ ((feed.articles.all()|count * 100 ) / nb_articles) | round(2, 'floor') }}% {{ _('of the database') }}) + ({{ ((feed.articles.all()|count * 100 ) / nb_articles) | round(2, 'floor') }}% {{ _('of the database') }}).
{% endif %} - .
+ + {% if feed.last_retrieved %} + {{ _("Last download:") }}

{{ feed.last_retrieved }}

+ {% endif %} + {% if feed.error_count > 2 %} - {{ _("That feed has encountered too much consecutive errors and won't be retreived anymore.") }} + {{ _("That feed has encountered too much consecutive errors and won't be retrieved anymore.") }}
{% elif feed.error_count > 0 %} - {{ _("That feed has encountered some errors but that counter will be reinitialized at the next successful retreiving.") }} + {{ _("The download of this feed has encountered some problems. However its error counter will be reinitialized at the next successful retrieving.") }}
{% endif %} -
+ {% if feed.last_error %} - {{ _("Here's the last error encountered while retreiving this feed:") }}
{{ feed.last_error }}
+ {{ _("Here's the last error encountered while retreiving this feed:") }}
{{ feed.last_error }}

{% endif %} {{ _('Address of the feed') }}: {{ feed.link }}
-- cgit