-
Notifications
You must be signed in to change notification settings - Fork 0
/
stravart.py
39 lines (30 loc) · 992 Bytes
/
stravart.py
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
32
33
34
35
36
37
38
39
"""Write current strava routes to synced folder
The main interesting properties are elevation_gain (m) distance(m) and estimated_moving_time
TODO move deleted to a Deleted/ subfolder, adding a deleted-date, and maybe a link to the strava activity?
"""
# /// script
# dependencies = [
# "strava-cli",
# "stravalib",
# ]
# ///
import json
import os
from stravalib import Client
import strava.api._helpers as strava_cli
dest = os.path.expanduser("~/OneDrive/Apps/StravaRoutes/")
existing = set(os.listdir(dest))
client = Client(requests_session=strava_cli.client)
for route in client.get_routes():
print(route.name)
text = route.json(exclude={"athlete"}, indent=2)
file_name = f"{route.id_str}.json"
with open(os.path.join(dest, file_name), "w") as f:
f.write(text)
existing.discard(file_name)
if existing:
print()
print("Deleted:")
for file_name in existing:
with open(os.path.join(dest, file_name), "r") as f:
print(file_name, json.load(f)["name"])