Browse Source

adding try's and except's to catch errors

master
manetta 3 years ago
parent
commit
e69bc8f998
  1. 47
      feedtools.py

47
feedtools.py

@ -17,23 +17,52 @@ def update():
for x, feed in enumerate(feeds): for x, feed in enumerate(feeds):
parsed = feedparser.parse(feed) parsed = feedparser.parse(feed)
if parsed: if parsed:
# print(f'Adding: { parsed.feed.title } ({ parsed.feed.link })') # print(f'\n\n-----------------\nAdding: { parsed.feed.title } ({ parsed.feed.link })')
x = str(x) x = str(x)
tmp['feeds'][x] = {} tmp['feeds'][x] = {}
if parsed.feed.title: if 'title' in parsed.feed:
tmp['feeds'][x]['title'] = parsed.feed.title tmp['feeds'][x]['title'] = parsed.feed.title
else: else:
tmp['feeds'][x]['title'] = "" tmp['feeds'][x]['title'] = ""
tmp['feeds'][x]['link'] = parsed.feed.link try:
tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base tmp['feeds'][x]['link'] = parsed.feed.link
tmp['feeds'][x]['description'] = parsed.feed.description except:
tmp['feeds'][x]['link'] = ""
try:
tmp['feeds'][x]['rss'] = parsed.entries[0].title_detail.base
except:
tmp['feeds'][x]['rss'] = ""
try:
tmp['feeds'][x]['description'] = parsed.feed.description
except:
tmp['feeds'][x]['description'] = ""
for post in parsed.entries: for post in parsed.entries:
year = post['published_parsed'][0]
month = post['published_parsed'][1] print(post)
day = post['published_parsed'][2] try:
post_date = date(year, month, day)
year = post['published_parsed'][0]
month = post['published_parsed'][1]
day = post['published_parsed'][2]
post_date = date(year, month, day)
except:
d, day, month, year, time = post['published'].split()
if month == "Jan": month = 1
if month == "Feb": month = 2
if month == "Mar": month = 3
if month == "Apr": month = 4
if month == "May": month = 5
if month == "Jun": month = 6
if month == "Jul": month = 7
if month == "Aug": month = 8
if month == "Sep": month = 9
if month == "Oct": month = 10
if month == "Nov": month = 11
if month == "Dec": month = 12
post_date = date(int(year), int(month), int(day))
if not str(post_date) in tmp['all_posts_sorted']: if not str(post_date) in tmp['all_posts_sorted']:
tmp['all_posts_sorted'][str(post_date)] = [] tmp['all_posts_sorted'][str(post_date)] = []

Loading…
Cancel
Save