Mercurial > lbo > hg > geohub
changeset 56:e47f25aef153
track_ICE: better collect logging
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Thu, 03 Dec 2020 22:38:54 +0100 |
parents | 1cbade934726 |
children | c4b26469b4e7 |
files | examples/track_ICE/README.md examples/track_ICE/collect.py |
diffstat | 2 files changed, 14 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/track_ICE/README.md Thu Dec 03 22:34:25 2020 +0100 +++ b/examples/track_ICE/README.md Thu Dec 03 22:38:54 2020 +0100 @@ -59,4 +59,11 @@ * Log it to a file consisting of JSON objects separated by newlines * Send it to a configured URL. -Run it with `--help` to obtain more info. +Run it with `--help` to obtain more info. Typically, you might run: + +```bash +$ ./collect.py --geohub_host=my.geohub.com --client=trainjourney007 +``` + +which will log the current location along with the complete train info returned +by the API (see above) as note to the specified GeoHub.
--- a/examples/track_ICE/collect.py Thu Dec 03 22:34:25 2020 +0100 +++ b/examples/track_ICE/collect.py Thu Dec 03 22:38:54 2020 +0100 @@ -9,6 +9,9 @@ import sys import time +def eprint(*args): + print(*args, file=sys.stderr) + def fetch_current(api): return requests.get(api).json() @@ -38,13 +41,14 @@ def run(args): info = fetch_current(args.api) if not info: - print('Empty info received!') + eprint('Empty info received!') return tzn = info['tzn'] - print('Running in train:', tzn) + eprint('Running in train:', tzn) 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')