aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-10-01 09:08:47 -0500
committerMark Powers <mark@marks.kitchen>2020-10-01 09:08:47 -0500
commitcd09508f35be208f16650e2ee0740bb6ff5afb15 (patch)
tree898f6213d6ac7071ae6f6f0e5b27827ca73abf2c
parentafaa20032fc773b9d2b0a1b7ac34ccabc70458d3 (diff)
Add error checking to on_this_day
-rw-r--r--on_this_day.py14
1 files changed, 13 insertions, 1 deletions
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 "<h1>On this day</h1><ul><li>%s</li><li>%s</li><li>%s</li><li>%s</li></ul>%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 "<h1>On this day</h1><ul><li>%s</li><li>%s</li><li>%s</li><li>%s</li></ul>%s" % (old_news, peanuts, calvin_and_hobbes, wikipedia, wikiquote)
def get_old_news():
print("getting old news")