From cd09508f35be208f16650e2ee0740bb6ff5afb15 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Thu, 1 Oct 2020 09:08:47 -0500 Subject: Add error checking to on_this_day --- on_this_day.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/on_this_day.py b/on_this_day.py index 5813f18..ea9e1e5 100644 --- a/on_this_day.py +++ b/on_this_day.py @@ -5,8 +5,20 @@ from bs4 import BeautifulSoup from config import config +def check_error(func, name): + try: + return func() + except: + return "Error getting %s" % name + def get_on_this_day(): - return "

On this day

%s" % (get_old_news(), get_peanuts(), get_calvin_and_hobbes(), get_today_wikipedia(), get_today_wikiquote()) + old_news = check_error(get_old_news, "old news") + peanuts = check_error(get_peanuts, "peanuts") + calvin_and_hobbes = check_error(get_calvin_and_hobbes, "calvin and hobbes") + wikipedia = check_error(get_today_wikipedia, "wikipedia") + wikiquote = check_error(get_today_wikiquote, "wikiquote") + + return "

On this day

%s" % (old_news, peanuts, calvin_and_hobbes, wikipedia, wikiquote) def get_old_news(): print("getting old news") -- cgit v1.2.3