From bfc4f02735c9c6f8a95503abfbb1d1c420169be5 Mon Sep 17 00:00:00 2001 From: manetta Date: Mon, 21 Feb 2022 15:41:50 +0100 Subject: [PATCH] adding a fallback for when feed URLs do not work --- feedtools.py | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/feedtools.py b/feedtools.py index 935744f..c3a4c58 100644 --- a/feedtools.py +++ b/feedtools.py @@ -15,30 +15,34 @@ def update(): for x, feed in enumerate(feeds): parsed = feedparser.parse(feed) - # print(parsed) - x = str(x) - - tmp['feeds'][x] = {} - tmp['feeds'][x]['title'] = parsed.feed.title - tmp['feeds'][x]['link'] = parsed.feed.link - tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base - tmp['feeds'][x]['description'] = parsed.feed.description - - for post in parsed.entries: - year = post['published_parsed'][0] - month = post['published_parsed'][1] - day = post['published_parsed'][2] - post_date = datetime(year, month, day, tzinfo=ZoneInfo("Europe/Amsterdam")) - - if not str(post_date) in tmp['all_posts_sorted']: - tmp['all_posts_sorted'][str(post_date)] = [] - - post['feed_details'] = {} - post['feed_details']['title'] = parsed.feed.title - post['feed_details']['link'] = parsed.feed.link - post['feed_details']['rss'] = parsed.entries[0].title_detail.base - post['feed_details']['description'] = parsed.feed.description - tmp['all_posts_sorted'][str(post_date)].append(post) + if parsed: + # print(f'Adding: { parsed.feed.title } ({ parsed.feed.link })') + x = str(x) + + tmp['feeds'][x] = {} + if parsed.feed.title: + tmp['feeds'][x]['title'] = parsed.feed.title + else: + tmp['feeds'][x]['title'] = "" + tmp['feeds'][x]['link'] = parsed.feed.link + tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base + tmp['feeds'][x]['description'] = parsed.feed.description + + for post in parsed.entries: + year = post['published_parsed'][0] + month = post['published_parsed'][1] + day = post['published_parsed'][2] + post_date = datetime(year, month, day, tzinfo=ZoneInfo("Europe/Amsterdam")) + + if not str(post_date) in tmp['all_posts_sorted']: + tmp['all_posts_sorted'][str(post_date)] = [] + + post['feed_details'] = {} + post['feed_details']['title'] = parsed.feed.title + post['feed_details']['link'] = parsed.feed.link + post['feed_details']['rss'] = parsed.entries[0].title_detail.base + post['feed_details']['description'] = parsed.feed.description + tmp['all_posts_sorted'][str(post_date)].append(post) db.update(tmp)