Created
August 7, 2019 16:16
-
-
Save chk1/510302afa11095bfae487a30ba69f1c5 to your computer and use it in GitHub Desktop.
Download Traccar data as GPX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.request | |
import base64 | |
params = { | |
"deviceId": "1", | |
"from": "2019-07-31T12:00:00+02:00", | |
"to": "2019-07-31T23:00:00+02:00" | |
} | |
outfile = "2019-07-31T12-23.gpx" | |
url = "https://traccar.example.com/api/positions?%s"%urllib.parse.urlencode(params) | |
print(url) | |
auth = "%s:%s" % ("admin", "secret") | |
basicauth = base64.b64encode(bytes(auth, "utf-8")).decode("ascii") | |
req = urllib.request.Request(url, headers={ | |
"Accept": "application/gpx+xml", | |
"Authorization": "Basic %s"%basicauth | |
}, method="GET") | |
f = urllib.request.urlopen(req) | |
response = f.read() | |
print("Response length", len(response)) | |
f.close() | |
with open(outfile, "wb") as gpxfile: | |
gpxfile.write(response) | |
gpxfile.close() | |
print(outfile,"ok") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment