Mercurial > lbo > hg > geohub
changeset 83:d136dc687455
Fix bug in ICE collection script
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sun, 06 Dec 2020 11:17:27 +0100 |
parents | 43da59d50223 |
children | 900d688cd1b9 |
files | examples/track_ICE/collect.py |
diffstat | 1 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/track_ICE/collect.py Sun Dec 06 11:03:41 2020 +0100 +++ b/examples/track_ICE/collect.py Sun Dec 06 11:17:27 2020 +0100 @@ -18,10 +18,13 @@ def format_server_time(servertime): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(servertime/1000)) -def send_point(args, info): +def send_point(args, info: dict[str, str]): geohub_url = args.geohub.format(HOST=args.geohub_host, CLIENT=args.client or info.get('tzn', 'TRAIN'), SECRET=args.secret, PROTOCOL=args.geohub_scheme) additional = '&lat={lat}&longitude={long}&spd={spd}&time={ts}'.format( lat=info['latitude'], long=info['longitude'], spd=info['speed'], ts=format_server_time(info['serverTime'])) + # Delete unnecessary data. + for k in ['latitude', 'longitude', 'speed', 'serverTime']: + info.pop(k) url = geohub_url + additional requests.post(url, json=info) @@ -48,11 +51,15 @@ with open(args.outfile, 'w') as outfile: while True: - eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info['serverTime']), info['longitude'], info['latitude'])) - send_point(args, info) - outfile.write(json.dumps(info)) - outfile.write('\n') + if info: + eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info['serverTime']), info['longitude'], info['latitude'])) + send_point(args, info) + outfile.write(json.dumps(info)) + outfile.write('\n') + else: + eprint('{} :: Skipped point due to no API response.'.format(format_server_time(time.time_ns()/1e6))) time.sleep(args.interval) + info = fetch_current(args.api) def main(): args = parse_args()