Skip to main content

Extends the Strava v3 API using web scraping

Project description

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

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Store the current session's information
jwt = client.jwt
access_token = client.access_token

# Create a new client that continues to use the previous web session
client = WebClient(access_token=access_token, jwt=jwt)

Extra functionality

Export activities

Download activity files as GPX, TCX, or the original format they were uploaded in.

from stravaweblib import WebClient, DataFormat

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first activity id (uses the normal stravalib API)
activities = client.get_activities()
activity_id = activities.next().id

# Get the filename and data stream for the activity data
data = client.get_activity_data(activity_id, fmt=DataFormat.ORIGINAL)

# Save the activity data to disk using the server-provided filename
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

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first activity id (uses the normal stravalib API)
activities = client.get_activities()
activity_id = activities.next().id

# Delete the activity
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

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get a list of bikes the current user owns
athlete = client.get_athlete()
bikes = athlete.bikes

# Get the id of the first bike
bike_id = bikes.next().id

# Get all components of the first bike (past and present)
client.get_bike_components(bike_id)

# Get the current components on the first bike
client.get_bike_components(bike_id, on_date=datetime.now())

Export routes

Download route files as GPX or TCX.

from stravaweblib import WebClient, DataFormat

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first route id (uses the normal stravalib API)
routes = client.get_routes()
route_id = routes.next().id

# Get the filename and data stream for the activity data
data = client.get_route_data(route_id, fmt=DataFormat.GPX)

# Save the activity data to disk using the server-provided filename
with open(data.filename, 'wb') as f:
    f.writelines(data.content)

License

Licensed under the Mozilla Public License, version 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stravaweblib-0.0.8.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

stravaweblib-0.0.8-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file stravaweblib-0.0.8.tar.gz.

File metadata

  • Download URL: stravaweblib-0.0.8.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.9

File hashes

Hashes for stravaweblib-0.0.8.tar.gz
Algorithm Hash digest
SHA256 7432a19ac72c0fa0c370a01a8fe51cd90a22fb64c1627c2ca64bc960899baadb
MD5 cb9fa67ce52fbcd6b8469fa818214b7a
BLAKE2b-256 1fe9103676f3dc0f408435ec809ec144dd3aa6085c7c15921b27448180363cf8

See more details on using hashes here.

File details

Details for the file stravaweblib-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for stravaweblib-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ea1a7e0f2dbe83896c45209dddd556f030890464dc3d616cc838734d07fd1415
MD5 564aff27fed3dd4faa528a0d6af6d7d6
BLAKE2b-256 8d2535cb6f850c64e88162cb51b3895817ddfdd56dd9496b618bd84bfb7e1dcc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page