-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrajectories_download.py
More file actions
32 lines (26 loc) · 1.06 KB
/
trajectories_download.py
File metadata and controls
32 lines (26 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from io import BytesIO
import traj_pb2 as Traj
import requests
from credentials import Credentials
import zipfile
headers = {
'accept': 'application/json',
# requests won't add a boundary if this header is set when you pass files=
# 'Content-Type': 'multipart/form-data',
}
n_skip = 0
limit = 30
# response = requests.post('https://openpositioning.org/api/live/trajectory/download/', headers=headers)
response = requests.get(f'https://openpositioning.org/api/live/trajectory/download/{Credentials.user_key}?skip={n_skip}&limit={limit}&key={Credentials.master_key}', headers=headers)
trajectories = []
with zipfile.ZipFile(BytesIO(response.content)) as zip_archive:
for item in zip_archive.filelist:
print(item.filename)
if item.filename.endswith(".pkt"):
trajectory = Traj.Trajectory()
try:
trajectory.ParseFromString(zip_archive.read(item.filename))
trajectories.append(trajectory)
print(str(trajectory)[:100])
except Exception as ex:
print(ex)