From 249a6165318e55c86d6a2aa16cf510e07a740ca9 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 16 Mar 2024 20:41:24 +0000 Subject: [PATCH] Alert on story update error --- apiserver/feed.py | 25 +++++++++++++++---------- apiserver/feeds/lobsters.py | 2 +- apiserver/utils.py | 8 ++++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/apiserver/feed.py b/apiserver/feed.py index 9b3635d..dac359b 100644 --- a/apiserver/feed.py +++ b/apiserver/feed.py @@ -68,16 +68,21 @@ def get_content_type(url): def update_story(story, is_manual=False): res = {} - if story['source'] == 'hackernews': - res = hackernews.story(story['ref']) - elif story['source'] == 'lobsters': - res = lobsters.story(story['ref']) - elif story['source'] == 'reddit': - res = reddit.story(story['ref']) - elif story['source'] == 'tildes': - res = tildes.story(story['ref']) - elif story['source'] == 'manual': - res = manual.story(story['ref']) + try: + if story['source'] == 'hackernews': + res = hackernews.story(story['ref']) + elif story['source'] == 'lobsters': + res = lobsters.story(story['ref']) + elif story['source'] == 'reddit': + res = reddit.story(story['ref']) + elif story['source'] == 'tildes': + res = tildes.story(story['ref']) + elif story['source'] == 'manual': + res = manual.story(story['ref']) + except BaseException as e: + utils.alert_tanner('Problem updating {} story, ref {}: {}'.format(story['source'], story['ref'], str(e))) + logging.exception(e) + return False if res: story.update(res) # join dicts diff --git a/apiserver/feeds/lobsters.py b/apiserver/feeds/lobsters.py index c9bab25..b2e1548 100644 --- a/apiserver/feeds/lobsters.py +++ b/apiserver/feeds/lobsters.py @@ -87,7 +87,7 @@ def story(ref): s = {} try: - s['author'] = r['submitter_user']['username'] + s['author'] = r['submitter_user'] s['author_link'] = SITE_AUTHOR_LINK(s['author']) except KeyError: s['author'] = '' diff --git a/apiserver/utils.py b/apiserver/utils.py index 9fbe3ee..7bf2bae 100644 --- a/apiserver/utils.py +++ b/apiserver/utils.py @@ -8,6 +8,14 @@ import string from bleach.sanitizer import Cleaner +def alert_tanner(message): + try: + logger.info('Alerting Tanner: ' + message) + params = dict(qotnews=message) + requests.get('https://tbot.tannercollin.com/message', params=params, timeout=4) + except BaseException as e: + logger.error('Problem alerting Tanner: ' + str(e)) + def gen_rand_id(): return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))