zs

Zeitungsschau rss to email converter
git clone git://r-36.net/zs
Log | Files | Refs | LICENSE

commit 0c5b34160ace6864f1ce5bf7ef797f0bc792f03b
parent a27ba4bf6d84464ebafcc9a4306ab829852a2cbf
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 31 Dec 2014 14:53:48 +0100

Fix breakup when there is no timestamp.

There was no tzoffset in now. Now there is UTC. It's the most compatible one.

Diffstat:
zeitungsschau/feed.py | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/zeitungsschau/feed.py b/zeitungsschau/feed.py @@ -11,6 +11,7 @@ from datetime import datetime import dateutil.parser import urllib.request, urllib.parse, urllib.error import hashlib +import pytz def parseiso(dstr, now): return dateutil.parser.parse(str(dstr), default=now) @@ -46,7 +47,7 @@ def parse(astr): articles = [] isrss = False isrdf = False - now = datetime.now() + now = datetime.now(pytz.utc) if hasattr(xml, "channel"): if hasattr(xml, "item"): @@ -141,11 +142,13 @@ def parse(astr): # updated if hasattr(entry, "updated"): - article["updated"] = parseiso(entry.updated) + article["updated"] = parseiso(entry.updated,\ + now) elif hasattr(entry, "pubDate"): - article["updated"] = parseiso(entry.pubDate) + article["updated"] = parseiso(entry.pubDate,\ + now) elif hasattr(entry, "date"): - article["updated"] = parseiso(entry.date) + article["updated"] = parseiso(entry.date, now) else: article["updated"] = now @@ -212,8 +215,12 @@ def parse(astr): # Will not process feeds with more than 64 entries. Can you hear me # Richard Stallman? - feed["articles"] = sorted(articles, key=lambda article: \ - article["updated"])[-64:] + try: + feed["articles"] = sorted(articles, key=lambda article: \ + article["updated"])[-64:] + except TypeError: + for article in articles: + print(article["updated"]) return feed