Mercurial > lbo > hg > geohub
changeset 121:cd36ca05c904
track_ICE: Use more efficient API for fetching points
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 16 Jan 2021 11:53:52 +0100 |
parents | 5c68b135deef |
children | cb2661200dab |
files | examples/track_ICE/collect.py |
diffstat | 1 files changed, 5 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/track_ICE/collect.py Sat Jan 16 09:23:36 2021 +0100 +++ b/examples/track_ICE/collect.py Sat Jan 16 11:53:52 2021 +0100 @@ -12,8 +12,8 @@ def eprint(*args): print(*args, file=sys.stderr) -def fetch_current(api): - return requests.get(api).json() +def fetch_current(sess, api): + return sess.get(api).json() def format_server_time(servertime): return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(servertime/1000)) @@ -42,7 +42,8 @@ return parser.parse_args() def run(args): - info = fetch_current(args.api) + session = requests.Session() + info = fetch_current(session, args.api) if not info: eprint('Empty info received!') return @@ -52,13 +53,11 @@ eprint('Running in train:', tzn) eprint('Go to LiveMap:', livemap_url); - session = requests.Session() - lastpoint = None with open(args.outfile, 'w') as outfile: while True: - info = fetch_current(args.api) + info = fetch_current(session, args.api) if lastpoint is None or lastpoint != (info['latitude'], info['longitude']): lastpoint = (info['latitude'], info['longitude']) if info: