From 3d543dd806f754f80af65c8f386bce9a0b3c9d6c Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Tue, 12 Mar 2019 18:40:28 -0500 Subject: [PATCH] naive single threaded approach --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a75a0b3..c2c4404 100755 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ import os import re import time import urllib +import subprocess # for logging import os.path as osp import sys @@ -15,6 +16,10 @@ CHICAGO_TZ = tz.gettz("America/Chicago") # https://stackoverflow.com/a/5967539 +def toast(text): + subprocess.check_call(["termux-toast",text]) + + def atoi(text): return int(text) if text.isdigit() else text @@ -122,6 +127,7 @@ def show(data, rt_filter=None, _clear=False): arrivals = filter(lambda arrival: arrival['rt'] == rt_filter, arrivals) if _clear: clearscr() + do_toast = True for bustime in arrivals: before = date_parse(bustime['prdtm']) arrival = before.replace(tzinfo=CHICAGO_TZ) @@ -133,12 +139,13 @@ def show(data, rt_filter=None, _clear=False): direction = bustime['rtdir'] end = bustime['des'] nm = bustime['stpnm'].rstrip() + if do_toast: + toast(config.format(**locals()) + '\n'*2+"\n") + do_toast = False print( config.format(**locals()), end='\n'*2 ) print("="*36) - - if __name__ == '__main__': parser = argparse.ArgumentParser(prog='ctabus') parser.add_argument('-l', '--lucky', action='store_true',