Year-to-date running stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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