Skip to content

Instantly share code, notes, and snippets.

@kerryb
Last active February 23, 2017 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerryb/e05dbe79965b15958e029111fcdeb540 to your computer and use it in GitHub Desktop.
Save kerryb/e05dbe79965b15958e029111fcdeb540 to your computer and use it in GitHub Desktop.
Year-to-date running stats
ytd() {
ytd=$(find ~/Dropbox/Apps/tapiriik -name $(date +%Y)-*_Running*.tcx -print0 | xargs -0 -n1 awk '/DistanceMeters/ {a=$0} END {gsub(/\s*<[^>]*>/, "", a); print a}' | paste -sd+ - | sed 's/\(.*\)/0.000621371 * (\1)/' | bc | sed 's/\(\..\).*/\1/')
proj=$(echo "$ytd * 365 / $(date +%j)" | bc)
echo "YTD: $ytd. Projected: $proj"
}
#! /usr/bin/env ruby
require "open-uri"
require "json"
open("https://www.strava.com/api/v3/athletes/#{ENV['STRAVA_ATHLETE_ID']}/stats",
"Authorization" => "Bearer #{ENV['STRAVA_TOKEN']}") do |f|
@response = f.read
end
metres = Integer JSON.parse(@response)["ytd_run_totals"]["distance"]
miles = metres / 1609
puts "Year to date: #{miles} miles"
day = Date.today.yday
puts "Projected annual total: #{miles * 365 / day} miles"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment