Skip to content

Instantly share code, notes, and snippets.

@kerryb
Last active Feb 23, 2017
Embed
What would you like to do?
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