From d24c0fba613219e0c2efae5dcc91ccbdab5089df Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 24 Apr 2019 14:09:47 -0500 Subject: [PATCH 1/2] fixed spam when network connection is dropped --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c18f440..61ae28d 100755 --- a/main.py +++ b/main.py @@ -188,12 +188,13 @@ def main(args): timeout = args.periodic data = ctabus.get_times(stop_id, timeout=timeout) e = time.perf_counter() - s - if e < args.periodic: - time.sleep(args.periodic-e) except KeyboardInterrupt: _done = True except (urllib.error.URLError, socket.timeout): + e = time.perf_counter() - s print("Error fetching times") + if e < args.periodic: + time.sleep(args.periodic-e) else: show(data, args.route) From 2c90177d7ee6643ae0c8f9db3e1fbac4c7d2fd7d Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Wed, 24 Apr 2019 16:37:15 -0500 Subject: [PATCH 2/2] added check to see if termux-toast is available --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 0c30140..2ac520f 100755 --- a/main.py +++ b/main.py @@ -14,6 +14,8 @@ import subprocess # for logging import os.path as osp import sys +import shutil +HAS_TOAST = shutil.which('termux-toast') is not None CHICAGO_TZ = tz.gettz("America/Chicago") DATETIME_FORMAT = "%A, %B %e, %Y %H:%M:%S" # https://stackoverflow.com/a/5967539 @@ -194,7 +196,7 @@ def main(args): _done = False while not _done: try: - show(data, args.route, True, args.disable_toast) + show(data, args.route, True, args.disable_toast and HAS_TOAST) s = time.perf_counter() timeout = 1 if args.periodic > timeout: