From 3d0a3f1577904404baafe0364e759976f5b5f91d Mon Sep 17 00:00:00 2001 From: Jason Schwarzenberger Date: Thu, 12 Nov 2020 15:08:23 +1300 Subject: [PATCH] support list based json-ld authors. --- apiserver/feeds/news.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apiserver/feeds/news.py b/apiserver/feeds/news.py index 7591cf5..a4ac7c9 100644 --- a/apiserver/feeds/news.py +++ b/apiserver/feeds/news.py @@ -102,7 +102,10 @@ def parse_extruct(s, data): if ld['datePublished']: s['date'] = ld['datePublished'] if 'author' in ld and ld['author']: - s['author'] = ld['author']['name'] + if 'name' in ld['author']: + s['author'] = ld['author']['name'] + elif len(ld['author']): + s['author'] = ld['author'][0]['name'] if '@graph' in ld: for gld in ld['@graph']: if '@type' in gld and gld['@type'] in ['Article', 'NewsArticle']: @@ -255,7 +258,12 @@ class Category(_Base): if __name__ == '__main__': print("Sitemap: The Spinoff") site = Sitemap("https://thespinoff.co.nz/sitemap.xml") - posts = site.feed() + excludes = [ + 'thespinoff.co.nz/sitemap-misc.xml', + 'thespinoff.co.nz/sitemap-authors.xml', + 'thespinoff.co.nz/sitemap-tax-category.xml', + ] + posts = site.feed(excludes) print(posts[:5]) print(site.story(posts[0]))