Browse Source

naive single threaded approach

no_compress
Raphael Roberts 7 years ago
parent
commit
3d543dd806
  1. 11
      main.py

11
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',

Loading…
Cancel
Save