Created
September 16, 2012 01:56
-
-
Save dorkrawk/3730736 to your computer and use it in GitHub Desktop.
This script takes in a Fitocracy username and uses my unofficial Fitocracy Runs API to return the total miles run for the user.
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
require 'rubygems' | |
require 'net/http' | |
require 'json' | |
require 'date' | |
if ARGV[0] | |
username = ARGV[0] | |
else | |
abort("You must supply a Fitocracy username.") | |
end | |
runs_url = "http://unofficial-fitocracy-runs-api.herokuapp.com/runs/#{username}" | |
runs_json = Net::HTTP.get_response(URI.parse(runs_url)).body | |
runs_info = JSON.parse(runs_json) | |
dist = 0 | |
date = '' | |
runs_info['runs'].each do |run| | |
dist = dist + run['distance_i'].to_i | |
date = run['datetime'] | |
end | |
start_date = DateTime.strptime(date).strftime('%B %e, %Y') | |
puts "#{username} has run #{dist.to_s} miles since #{start_date.to_s}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment