From 4e00328786c71025725104a1b4f428b379ef55d7 Mon Sep 17 00:00:00 2001 From: grym Date: Sat, 22 Jan 2022 15:32:30 -0500 Subject: [PATCH] handle missing URLs more gracefully --- fedmon/cli.py | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/fedmon/cli.py b/fedmon/cli.py index 8475b2c..612f594 100644 --- a/fedmon/cli.py +++ b/fedmon/cli.py @@ -114,24 +114,28 @@ def main( prev = None counter = itertools.count() while True: - data = get_data(config.base_url) - data = parse_data(data) - summary = analyze_data(data) - if summary != prev: - if summary.sites: - typer.echo(format_response(summary, format, next(counter))) - if send_notification: - try: - subprocess.check_call( - [ - "notify-send", - appname, - format_response( - summary, AllowedFormat.json, next(counter) - ), - ] - ) - except subprocess.CalledProcessError as e: - typer.echo(e, err=True) - prev = summary - time.sleep(config.poll) + try: + data = get_data(config.base_url) + data = parse_data(data) + summary = analyze_data(data) + if summary != prev: + if summary.sites: + typer.echo(format_response(summary, format, next(counter))) + if send_notification: + try: + subprocess.check_call( + [ + "notify-send", + appname, + format_response( + summary, AllowedFormat.json, next(counter) + ), + ] + ) + except subprocess.CalledProcessError as e: + typer.echo(e, err=True) + prev = summary + except httpx.ConnectError as e: + typer.echo(e, err=True) + finally: + time.sleep(config.poll)