Mercurial > lbo > hg > geohub
changeset 146:9b86bc651228
Merge heads again
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Mon, 08 Aug 2022 17:35:39 +0200 |
parents | 52cd2f83ce85 (diff) 5899914fea06 (current diff) |
children | 51004e96b2d0 |
files | examples/track_ICE/collect.py |
diffstat | 3 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.lock Fri Mar 11 11:39:23 2022 +0100 +++ b/Cargo.lock Mon Aug 08 17:35:39 2022 +0200 @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "addr2line" version = "0.14.0" @@ -140,6 +142,12 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1150,12 +1158,12 @@ [[package]] name = "rocket" -version = "0.4.6" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fc7e5d6aaa32ace6893ae8a1875688ca7b07d6c2428ae88e704c3623c8866e9" +checksum = "4a7ab1dfdc75bb8bd2be381f37796b1b300c45a3c9145b34d86715e8dd90bf28" dependencies = [ "atty", - "base64 0.12.3", + "base64 0.13.0", "log 0.4.11", "memchr 2.3.4", "num_cpus", @@ -1171,9 +1179,9 @@ [[package]] name = "rocket_codegen" -version = "0.4.6" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "519154b16df5fe552a8f9cd76a97793a9f5d58e34f186ab79c7b29ce1d009358" +checksum = "1729e687d6d2cf434d174da84fb948f7fef4fac22d20ce94ca61c28b72dbcf9f" dependencies = [ "devise", "glob", @@ -1215,9 +1223,9 @@ [[package]] name = "rocket_http" -version = "0.4.6" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d087de7203c7a60a0ed5cd3a135b552dbfbed9932c52d49d083e8629935257" +checksum = "6131e6e6d38a9817f4a494ff5da95971451c2eb56a53915579fc9c80f6ef0117" dependencies = [ "cookie", "hyper",
--- a/Cargo.toml Fri Mar 11 11:39:23 2022 +0100 +++ b/Cargo.toml Mon Aug 08 17:35:39 2022 +0200 @@ -7,7 +7,7 @@ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rocket = "~0.4" +rocket = "~0.4.10" postgres = { version = "~0.15", features = ["with-chrono"] } chrono = { version = "^0.4", features = ["serde"] } serde = { version = "~1.0", features = ["derive"] }
--- a/examples/track_ICE/collect.py Fri Mar 11 11:39:23 2022 +0100 +++ b/examples/track_ICE/collect.py Mon Aug 08 17:35:39 2022 +0200 @@ -15,7 +15,8 @@ def fetch_current(sess, api): while True: try: - return sess.get(api).json() + js = sess.get(api) + return js.json() except Exception as e: eprint('Retrying failed request:', e) time.sleep(5) @@ -27,10 +28,11 @@ geohub_templ = args.geohub + '/{CLIENT}/log?secret={SECRET}' geohub_url = geohub_templ.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}&s={spd}&time={ts}'.format( - lat=info['latitude'], long=info['longitude'], spd=info['speed'], ts=format_server_time(info['serverTime'])) + lat=info['latitude'], long=info['longitude'], spd=info.get('speed', 0), ts=format_server_time(info.get('serverTime', time.time()*1e3))) # Delete unnecessary data. for k in ['latitude', 'longitude', 'speed', 'serverTime']: - info.pop(k) + if k in info: + info.pop(k) url = geohub_url + additional try: sess.post(url, json=info) @@ -48,15 +50,19 @@ parser.add_argument('--geohub_host', default='example.com', help='Host of your GeoHub. Use this if the URL --geohub works for you.') parser.add_argument('--geohub_scheme', default='https', help='Protocol scheme of the GeoHub instance. Use this if you do not want to specify the entire --geohub URL') parser.add_argument('--geohub', default='{PROTOCOL}://{HOST}/geo/', help='Base URL of Geohub instance. E.g., https://example.com/geo. Use --geohub_host, --geohub_scheme if your URL looks like the example.') + parser.add_argument('--sbb', action='store_const', const=True, default=False, help='Use on SBB trains with on-board Wi-Fi') return parser.parse_args() def run(args): + if args.sbb: + args.api = 'https://onboard.sbb.ch/services/pis/v1/position' + session = requests.Session() info = fetch_current(session, args.api) if not info: eprint('Empty info received!') return - tzn = info['tzn'] + tzn = info.get('tzn', 'SBB_EC') geohub_base = args.geohub.format(PROTOCOL=args.geohub_scheme, HOST=args.geohub_host) livemap_url = geohub_base + 'assets/livemap.html?client={client}&secret={secret}'.format(client=args.client, secret=args.secret) eprint('Running in train:', tzn) @@ -70,7 +76,7 @@ if lastpoint is None or lastpoint != (info['latitude'], info['longitude']): lastpoint = (info['latitude'], info['longitude']) if info: - eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info['serverTime']), info['longitude'], info['latitude'])) + eprint('{} :: Sending point ({}, {}) to GeoHub.'.format(format_server_time(info.get('serverTime', time.time()*1e3)), info['longitude'], info['latitude'])) send_point(session, args, info) outfile.write(json.dumps(info)) outfile.write('\n')