zs

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

commit ee341c7915c2d85c90eb6deef11c964fb88986fa
parent 19899f9da5895c6493f499e00cd0feec00732f1f
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 20 Dec 2017 18:41:05 +0100

In case no items are defined in a jsonfeed, don't bail.

Diffstat:
zeitungsschau/feed.py | 97++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 49 insertions(+), 48 deletions(-)

diff --git a/zeitungsschau/feed.py b/zeitungsschau/feed.py @@ -100,59 +100,60 @@ def parsejsonfeed(astr): feed["author"] = js["author"]["name"] feed["updated"] = now - for item in js["items"]: - article = {} - if "url" in item: - article["file"] = item["url"] - if "title" in item: - article["title"] = item["title"] - if "id" in item: - article["id"] = item["id"] - else: - if "link" in article: - article["id"] = article["link"] - elif "file" in article: - article["id"] = article["file"] + if "items" in js: + for item in js["items"]: + article = {} + if "url" in item: + article["file"] = item["url"] + if "title" in item: + article["title"] = item["title"] + if "id" in item: + article["id"] = item["id"] else: - article["id"] = article["text"][:30] - - if "summary" in item: - article["text"] = html.unescape(item["summary"]) - if "content_html" in item: - article["text"] = html.unescape(item["content_html"]) - if "content_text" in item: - article["text"] = html.unescape(item["content_text"]) - if "date_published" in item: - article["updated"] = \ - dateutil.parser.parse(item["date_published"]) - else: - article["updated"] = now + if "link" in article: + article["id"] = article["link"] + elif "file" in article: + article["id"] = article["file"] + else: + article["id"] = article["text"][:30] - if article["updated"] == now: - article["uuid"] = "" - else: - article["uuid"] = "%s" % (article["updated"]) + if "summary" in item: + article["text"] = html.unescape(item["summary"]) + if "content_html" in item: + article["text"] = html.unescape(item["content_html"]) + if "content_text" in item: + article["text"] = html.unescape(item["content_text"]) + if "date_published" in item: + article["updated"] = \ + dateutil.parser.parse(item["date_published"]) + else: + article["updated"] = now - for e in ("id", "title", "file"): - if e in article: - article["uuid"] = "%s-%s" % \ - (article["uuid"],\ - article[e]) - - def mkuuid(s): - return hashlib.sha256(str(s).\ - encode("utf8")).hexdigest() - if len(article["uuid"]) == 0: - article["uuid"] = mkuuid(now) - else: - article["uuid"] = mkuuid(article["uuid"]) + if article["updated"] == now: + article["uuid"] = "" + else: + article["uuid"] = "%s" % (article["updated"]) - # sanity checks - if "title" not in article and "text" not in article \ - and "file" not in article: - continue + for e in ("id", "title", "file"): + if e in article: + article["uuid"] = "%s-%s" % \ + (article["uuid"],\ + article[e]) - articles.append(article) + def mkuuid(s): + return hashlib.sha256(str(s).\ + encode("utf8")).hexdigest() + if len(article["uuid"]) == 0: + article["uuid"] = mkuuid(now) + else: + article["uuid"] = mkuuid(article["uuid"]) + + # sanity checks + if "title" not in article and "text" not in article \ + and "file" not in article: + continue + + articles.append(article) feed["articles"] = articles