handle missing URLs more gracefully

This commit is contained in:
grym 2022-01-22 15:32:30 -05:00
parent 6ecb7c0430
commit 4e00328786
1 changed files with 25 additions and 21 deletions

View File

@ -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)