Last active
          February 23, 2017 21:45 
        
      - 
      
- 
        Save kerryb/e05dbe79965b15958e029111fcdeb540 to your computer and use it in GitHub Desktop. 
    Year-to-date running stats
  
        
  
    
      This file contains hidden or 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 hidden or 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