Author Topic: Command line strava uploader  (Read 757 times)

Kim

  • Timelord
Command line strava uploader
« on: May 05, 2020, 12:24:57 am »
From the Fettled any computer stuff today? thread:

Bash script for uploading GPX files to Strava.

I'd been using one that was mentioned by a forumite to good effect for ages, but at some point last year they changed the API and b0rked the authentication.

In the absence of anything better to do, I sat down with the relevant docs and cURL and worked out how to authenticate.

Having achieved that, I started tweaking things, so it's now many hours later a bit more featureful than I actually need.  But I've probably learned something about bash's semi-comprehensible handling of quotes, or at least how to avoid the worst of it.  Not that I'll remember any of it for next time.

I've wanged it on GitHub in case it's of use to anyone (presumably unisex spaceadmins using eTrex-like GPS receivers): https://github.com/kimble4/strava_upload
Careful, Kim. Your sarcasm's showing...

Command line strava uploader
« Reply #1 on: May 05, 2020, 09:58:26 am »
Nice. Next task - mini web server in Perl or php running on local host to pick up token on redirect to save manual copying.


Sent from my iPad using Tapatalk

JonB

  • Granny Ring ... Yes Please!
Re: Command line strava uploader
« Reply #2 on: May 05, 2020, 11:35:32 am »
From the Fettled any computer stuff today? thread:

Bash script for uploading GPX files to Strava.

I'd been using one that was mentioned by a forumite to good effect for ages, but at some point last year they changed the API and b0rked the authentication.

In the absence of anything better to do, I sat down with the relevant docs and cURL and worked out how to authenticate.

Having achieved that, I started tweaking things, so it's now many hours later a bit more featureful than I actually need.  But I've probably learned something about bash's semi-comprehensible handling of quotes, or at least how to avoid the worst of it.  Not that I'll remember any of it for next time.

I've wanged it on GitHub in case it's of use to anyone (presumably unisex spaceadmins using eTrex-like GPS receivers): https://github.com/kimble4/strava_upload

Apologies for naive questions from an Etrex user ... what does it do and how/why would I use it?

Kim

  • Timelord
Re: Command line strava uploader
« Reply #3 on: May 05, 2020, 12:15:43 pm »
Apologies for naive questions from an Etrex user ... what does it do and how/why would I use it?

It uploads GPX files to strava in a conveniently *nix-ish way, without having to use the website or any of the Garmin tools that aren't available on Linux.

Probable use cases:

1) You're a Linux desktop user who prefers to do things at the command line rather than mousing around on websites.

2) You want to automate uploads to Strava from a script for some reason (eg. maybe you want to batch process a historical archive of GPX files).

3) You could use it as a component in some clever workflow (eg. you could email yourself a GPX from your mobile device while touring, some script picks it up, saves a copy in your archive and uses this script to upload it to Strava).

4) And I admit this isn't entirely clear in the readme: You have an eTrex 30 and want Strava to use the device's elevation readings, rather than extrapolating them from a map.  This script spots that a GPX has come from an eTrex 30 and appends " with barometer" to the relevant field before uploading (see 'Device and Elevation Data' on https://developers.strava.com/docs/uploads/ for details).  Having one tool to do this and the upload in a single action is much easier than faffing about with sed or a text editor and then uploading manually via the website.


TBH, it's mostly one of those "if you have to ask, you probably don't need it" things.
Careful, Kim. Your sarcasm's showing...

JonB

  • Granny Ring ... Yes Please!
Re: Command line strava uploader
« Reply #4 on: May 05, 2020, 09:47:50 pm »
Apologies for naive questions from an Etrex user ... what does it do and how/why would I use it?
3) You could use it as a component in some clever workflow (eg. you could email yourself a GPX from your mobile device while touring, some script picks it up, saves a copy in your archive and uses this script to upload it to Strava).

4) And I admit this isn't entirely clear in the readme: You have an eTrex 30 and want Strava to use the device's elevation readings, rather than extrapolating them from a map.  This script spots that a GPX has come from an eTrex 30 and appends " with barometer" to the relevant field before uploading (see 'Device and Elevation Data' on https://developers.strava.com/docs/uploads/ for details).  Having one tool to do this and the upload in a single action is much easier than faffing about with sed or a text editor and then uploading manually via the website.
Thanks Kim,
3 is interesting and I can see a use for that.
4 - I do the 'with barometer' thing manually, so this is a way of not getting into the text file and inserting words? That's potentially useful

TBH, it's mostly one of those "if you have to ask, you probably don't need it" things.
Yes, I suspected this but the Etrex angle piqued my interest. If I could work out what a script is and how I could use it then I could be in business (I do have a vague idea and might explore it when I have the time).
Thanks again for replying and for sharing the tool

Kim

  • Timelord
Re: Command line strava uploader
« Reply #5 on: May 05, 2020, 09:56:40 pm »
4 - I do the 'with barometer' thing manually, so this is a way of not getting into the text file and inserting words? That's potentially useful

Yeah, when fed an uncompressed GPX file it searches for creator="eTrex 30" and replaces[1] it with creator="eTrex 30 with barometer" before uploading it to strava.  Much less faffing around.


Quote
If I could work out what a script is and how I could use it then I could be in business (I do have a vague idea and might explore it when I have the time).

It's a Bash script, so easily used on most Linux systems if you're familiar with doing things at the command line.  Probably reasonably straightforward on OSX (again, if you know what you're doing at the command line).  Windows is likely to be a problem, as it lacks most of the standard tools and tends to do things differently, so I wouldn't be surprised if it doesn't work properly in a windows Bash environment without modification by someone who knows what they're doing.


(FWIW, I've written the odd computer program in my time, but my shell-script-fu is distinctly lacking, as I tend to go too long between needing to write them and forget most of what I learned.)



[1] You can do this sort of find-and-replace quickly and efficiently with the command-line tool 'sed', which should be available on most *nixes:
Code: [Select]
sed --in-place=.bak 's/creator="eTrex 30"/creator="eTrex 30 with barometer"/' myFile.gpxwill perform the find-and-replace (and create an unmodified backup file).
Careful, Kim. Your sarcasm's showing...

Re: Command line strava uploader
« Reply #6 on: May 06, 2020, 12:00:44 am »
Nice.
Wouldnt have any need for it myself as I just use the strava app... But quite nifty

I can't see any reason why it wouldn't work on windows with gnu tools installed and in the path
It is what it is. It's not what it's not, so it must be what it is.