Mercurial > lbo > hg > geohub
changeset 140:adf70726032a
track_ICE: improve exception handling
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 15 Aug 2021 15:52:59 +0200 |
parents | 56a1bb72731e |
children | 04cc04ca4d5c 32a35be9c506 5899914fea06 |
files | examples/track_ICE/collect.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/track_ICE/collect.py Sat May 22 23:51:01 2021 +0200 +++ b/examples/track_ICE/collect.py Sun Aug 15 15:52:59 2021 +0200 @@ -16,9 +16,9 @@ while True: try: return requests.get(api).json() - except requests.exceptions.ConnectionError as e: + except Exception as e: eprint('Retrying failed request:', e) - time.sleep(3) + time.sleep(5) def format_server_time(servertime): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(servertime/1000)) @@ -32,7 +32,11 @@ for k in ['latitude', 'longitude', 'speed', 'serverTime']: info.pop(k) url = geohub_url + additional - sess.post(url, json=info) + try: + sess.post(url, json=info) + except Exception as e: + eprint('Failed sending point; giving up for now') + return def parse_args(): parser = argparse.ArgumentParser(description='Fetch and send train data')