Sunday, November 30, 2014

strava node.js api

How to get shoe mileage on the command line


make sure you have node.js and node package manager (npm) installed.
$ sudo apt-get install node.js npm

then follow this quickstart instructions  from here: https://github.com/ajsnapshots/node-strava-v3

get strava developer api access from here
access your application info and settings here: https://app.strava.com/settings/api
the api doc is at: http://strava.github.io/api/

now you should be able to run the example program from the quickstart guide.


you directory structure should look something like this:


user@host:~/Programming/node.js/strava$ tree -L 2
.
├── data
│   └── strava_config
├── node_modules
│   └── strava-v3
└── shoes.js

3 directories, 2 files

now edit the shoes.js file and put in this code:
user@host:~/Programming/node.js/strava$ cat shoes.js 

var strava = require('strava-v3');

strava.athlete.get({},function(err,payload) {
    if(!err) {          
for (var i=0; i<payload.shoes.length; i++) {
   console.log(payload.shoes[i].name + " - " +
payload.shoes[i].distance/1000 + " km");
}

    }   
    else {
console.log("ERROR:");
        console.log(err);
    }
});

if you run it you should get a listing of your active shoes from strava together with the mileage (here in km)

$ node shoes.js 
Salomon Fellraiser - 481.693 km
Inov-8 Roclite 315 - 383.47 km
Brooks T6 Racer - 401.136 km
Inov-8 Trailroc 255 - 656.62 km
Saucony Fastwitch 5 ( blue ) - 463.049 km
Barefoot (No Shoes) - 5.219 km
Aldi "barfuss" ?? blau - 136.115 km
Saucony Peregrine 3.0 - 479.282 km
Hoka One One Mafata 2 - 1119.308 km
New Balance Minimum Trail 00 - 403.544 km
Inov-8 Trailrc 245 - 338.791 km
Vibram FF EL-X - 46.919 km


that's it for now.

No comments: