stravaweblib
Provides all the functionality of the stravalib package and
extends it using web scraping.
Authentication
In order to log into the website, the WebClient
class either needs an email and password, or the
JWT of an existing session. Strava stores this JWT
in the strava_remember_token
cookie.
After the client has logged in, a JWT for the current session can be accessed via the WebClient
's
jwt
property. Storing this JWT (and the access_token
from stravalib
) allows for resuming the
session without having to log in again. This can avoid rate limits and lockouts.
Example:
from stravaweblib import WebClient
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)
jwt = client.jwt
access_token = client.access_token
client = WebClient(access_token=access_token, jwt=jwt)
Export activities
Download activity files as GPX, TCX, or the original format they were uploaded in.
from stravaweblib import WebClient, DataFormat
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)
activities = client.get_activities()
activity_id = activities.next().id
data = client.get_activity_data(activity_id, fmt=DataFormat.ORIGINAL)
with open(data.filename, 'wb') as f:
f.writelines(data.content)
Delete activities
Delete activities from the site. Note that this was previously possible via the API, but the
endpoint has been removed as of 2017-01-17.
from stravaweblib import WebClient
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)
activities = client.get_activities()
activity_id = activities.next().id
client.delete_activity(activity_id)
Get bike components
Retrieve all components added to bikes. Can optionally only show components active at a certain date.
from stravaweblib import WebClient
from datetime import datetime
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)
athlete = client.get_athlete()
bikes = athlete.bikes
bike_id = bikes.next().id
client.get_bike_components(bike_id)
client.get_bike_components(bike_id, on_date=datetime.now())
Export routes
Download route files as GPX or TCX.
from stravaweblib import WebClient, DataFormat
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)
routes = client.get_routes()
route_id = routes.next().id
data = client.get_route_data(route_id, fmt=DataFormat.GPX)
with open(data.filename, 'wb') as f:
f.writelines(data.content)
License
Licensed under the Mozilla Public License, version 2.0