Browse Source

adding a fallback for when feed URLs do not work

master
manetta 3 years ago
parent
commit
bfc4f02735
  1. 52
      feedtools.py

52
feedtools.py

@ -15,30 +15,34 @@ def update():
for x, feed in enumerate(feeds): for x, feed in enumerate(feeds):
parsed = feedparser.parse(feed) parsed = feedparser.parse(feed)
# print(parsed) if parsed:
x = str(x) # print(f'Adding: { parsed.feed.title } ({ parsed.feed.link })')
x = str(x)
tmp['feeds'][x] = {}
tmp['feeds'][x]['title'] = parsed.feed.title tmp['feeds'][x] = {}
tmp['feeds'][x]['link'] = parsed.feed.link if parsed.feed.title:
tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base tmp['feeds'][x]['title'] = parsed.feed.title
tmp['feeds'][x]['description'] = parsed.feed.description else:
tmp['feeds'][x]['title'] = ""
for post in parsed.entries: tmp['feeds'][x]['link'] = parsed.feed.link
year = post['published_parsed'][0] tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base
month = post['published_parsed'][1] tmp['feeds'][x]['description'] = parsed.feed.description
day = post['published_parsed'][2]
post_date = datetime(year, month, day, tzinfo=ZoneInfo("Europe/Amsterdam")) for post in parsed.entries:
year = post['published_parsed'][0]
if not str(post_date) in tmp['all_posts_sorted']: month = post['published_parsed'][1]
tmp['all_posts_sorted'][str(post_date)] = [] day = post['published_parsed'][2]
post_date = datetime(year, month, day, tzinfo=ZoneInfo("Europe/Amsterdam"))
post['feed_details'] = {}
post['feed_details']['title'] = parsed.feed.title if not str(post_date) in tmp['all_posts_sorted']:
post['feed_details']['link'] = parsed.feed.link tmp['all_posts_sorted'][str(post_date)] = []
post['feed_details']['rss'] = parsed.entries[0].title_detail.base
post['feed_details']['description'] = parsed.feed.description post['feed_details'] = {}
tmp['all_posts_sorted'][str(post_date)].append(post) 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) db.update(tmp)

Loading…
Cancel
Save