Code Monkey home page Code Monkey logo

sls's Introduction

sls

ls for Strava activities. Makes finding old things easier.

$ sls
#     Date       ID  Type   Dist   Elev  Gear   Name
2010-06-04  2063782  Ride   85.5   1478  Focus  06/04/2010 Megève, Rhône-Alpes, France
2010-06-05  2065048  Ride  166.5   3555  Focus  Megeve sportive warm-up
2010-06-06  2065038  Ride  114.0   2821  Focus  Time Megeve sportive
2010-06-07  2065018  Ride   58.8   1507  Focus  06/07/2010 Megève, Rhône-Alpes, France
[..]

If you're an fzf fan this shortcut will allow you to select multiple activities and open them in your browser:

$ type -f strava
strava () {
    sls \
    | fzf --multi --no-sort --tac --header-lines=1 \
    | awk '{ print "https://www.strava.com/activities/" $2 }' \
    | xargs open
}

Demo of sls + fzf (click for video):

asciicast

Another use: tracking how many kilometers a chain has:

$ type -f chain-dist
chain-dist () {
    id=$(cat ~/.chain-id)
    sls -j \
    | jq -r '.[] | "\(.activity.id)\t\(.activity.type)\t\(.activity.external_id)\t\(.gear.name)\t\(.activity.distance)"' \
    | awk -v id=$id '
        $1 == id {
            go = 1
        }
        {
            if (go && $4 == "R3") {
                if ($2 == "VirtualRide" || $3 ~ /^(trainerroad|zwift)/) {
                    vkm += $5
                }
                km += $5
                n++
            }
        }
        END {
            printf("%d rides, %d km (%d km indoors)\n", n, km / 1000, vkm / 1000)
        }'
}

$ echo 3179772474 > ~/.chain-id  # first activity on new chain

$ chain-dist
64 rides, 2587 km (1797 km indoors)

Building

$ git clone [email protected]:markdrayton/sls.git
$ cd sls/cmd/sls
$ go build

Configuration

Follow the Strava API setup guide. Make sure you request the read and activity:read_all scopes to see all of your activities. Grab the resulting client ID, client secret, and JSON token blob. Then:

$ mkdir ~/.sls
$ cat <<EOF > ~/.sls/config.toml
athlete_id = <your athlete ID>
client_id = <client ID>
client_secret = "<client secret>"
EOF

Paste the JSON token blob into ~/.sls/token. The config file and token probably shouldn't be world readable.

Without an existing cache sls will fetch activities in parallel. Once a cache is present it will only fetch activities that have occurred since the latest cached activity. The cache is never automatically dropped so any changes made to cached activities won't be locally reflected. Use sls -r to force a cache refresh.

The Strava API doesn't return geocoded start locations (for sls -s). sls can use the Google Maps API for this purpose by setting a valid google_maps_api_key in config.toml. To reduce the number of calls to the geocoding API start lat/lng values are rounded to 2km boundaries and the geocoded locations are cached in ~/.sls.

sls's People

Contributors

markdrayton avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.