Skip to content

Commit f4a0d21

Browse files
committed
Create modify_set_commute.py
1 parent 9b025bf commit f4a0d21

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/modify_set_commute.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Modify Activity: set commute."""
2+
3+
import requests
4+
5+
# obtain token from Strava V1 Perl App
6+
token = ""
7+
8+
# list of activities where I want to set the commute flag
9+
ACTIVITIES = {16851917279}
10+
11+
12+
def _api_put(url: str, data: dict) -> dict | list:
13+
try:
14+
resp = requests.put(url=url, data=data, headers=HEADERS, timeout=(3, 30))
15+
resp.raise_for_status()
16+
return resp.json()
17+
except requests.RequestException as e:
18+
print(e)
19+
return {}
20+
21+
22+
# from helper_api import URL_BASE
23+
URL_BASE = "https://www.strava.com/api/v3"
24+
HEADERS = {"Authorization": f"Bearer {token}"}
25+
BODY = {"commute": True}
26+
27+
for activity_id in ACTIVITIES:
28+
print(activity_id)
29+
url = URL_BASE + "/activities/" + str(activity_id)
30+
resp_dict = _api_put(url=url, data=BODY)
31+
assert type(resp_dict) is dict
32+
print(resp_dict["id"], resp_dict["name"])

0 commit comments

Comments
 (0)