lorenzobenvenuti / strava-cli

Command Line Interface for Strava
MIT License
4 stars 1 forks source link
cli strava strava-cli

strava-cli

Command line interface for Strava. It allows to:

Using strava-cli

$ ./strava-cli.py -h
usage: strava-cli.py [-h]
                     {activities,details,gps,update,bikes,shoes,clear-cache,authenticate}
                     ...

Strava Command Line Interface

positional arguments:
  {activities,details,gps,update,bikes,shoes,clear-cache,authenticate}
    activities          List activities according to specified filters
    details             Retrieves the details of one or more activities
    gps                 Retrieves the gps file of one or more activities
    update              Update one or more activities
    bikes               Retrieve bikes
    shoes               Retrieve shoes
    clear-cache         Clear the cache
    authenticate        Authenticate using a client secret and client id

optional arguments:
  -h, --help            show this help message and exit

Setup

To use strava-cli you will need python3 and these dependencies:

You can install them if you have pip for python3:

Obtaining a token

Strava uses a 3-legged OAuth flow in order to allow the application to access user data. In the Settings page, My API Application section, you can find an authorization token... which actually doesn't work: some API calls (retrieving activites, for instance), return an empty result.

To obtain an access token:

Retrieving activities

You can retrieve your activities using the activities subcommand. Activities are downloaded and cached locally; every time the command is run the application checks if new activities have been uploaded. To clear the cache you can use the Command

$ ./strava-cli.py clear-cache

The activities command accepts some arguments:

$ ./strava-cli.py activities -h
usage: strava-cli.py activities [-h] [--filter FILTER] [--quiet]

optional arguments:
  -h, --help            show this help message and exit
  --filter FILTER, -f FILTER
                        Adds a filter to the query
  --quiet, -q           Prints only activity identifiers

The --filter (or -f) option allows you to filter activities. Supported filters are:

Some examples:

$ ./strava-cli activities
$ ./strava-cli activities -f private=1
$ ./strava-cli activities -f private=1 -f after=201701 -f before=201702
$ ./strava-cli.py activities -f before=20161231 -f after=20160101 -f  elevation=1200-

Retrieving activity details

$ ./strava-cli.py details <activity-id>

Retrieving GPS track

To print the track to stdout in GPX format:

$ ./strava-cli.py gps <activity-id>

Instead, if you want to retrieve the track in JSON format:

$ ./strava-cli.py gps -j <activity-id>

Updating activities

You can update one ore more activities using the update command. The syntax is:

$ ./strava-cli.py update -h
usage: strava-cli.py update [-h] --set SET id [id ...]

positional arguments:
  id                 Activity id(s)

optional arguments:
  -h, --help         show this help message and exit
  --set SET, -s SET  Sets a property

Supported properties are described in the Strava API v3 specification.

When an update operation is performed the cache is updated accordingly; on the other hand updating an activity using another requires to clear the strava-cli cache in order to see the updated values.

$ ./strava-cli.py update -s "name=New activity name" -s "description=New activity description" <activity-id>
$ ./strava-cli.py update -s private=true $(./strava-cli.py -t <token> activities -q -f trainer=true)

Listing gear

$ ./strava-cli.py bikes
$ ./strava-cli.py shoes

TODO