Fitocracy is a great site for tracking exercise, one which manages to have both a very friendly culture and an impressively gung-ho attitude. But they've never gotten around to implementing any kind of official API. If you want to look up your Fitocracy score from inside a script, you need to jump through a surprising number of hoops.
First, let's create a Ruby
Gemfile. We'll use
capybara-webkit, which is
normally used for testing Ruby websites:
source "https://rubygems.org" gem "capybara" gem "capybara-webkit" # Optional, if you want to debug using save_and_open_page. #gem 'launchy'
These gems can be installed using
Next, let's include the necessary libraries in our Ruby script, and
configure Capybara as described in this handy article on using
Capybara in place of
require "capybara" require "capybara/dsl" require "capybara-webkit" # Optional, if you want to debug using save_and_open_page. #require "launchy" Capybara.run_server = false Capybara.current_driver = :webkit Capybara.app_host = "https://www.fitocracy.com/"
class FitoCrawler include Capybara::DSL def initialize(username, password) visit('/') click_on('Log in') find('.login-username-link').click fill_in('username-login-username', with: username) fill_in('username-login-password', with: password) find('#username-login-submit').click end def score click_on('You') # Want to see what's going on? Enable 'lauchy' to use this. #save_and_open_page # Grab the score, filter out ',', and convert to an integer. find('#stat-points .stat-value').text.gsub(/,/, '').to_i end end
To use this, run:
score = FitoCrawler.new(FITOCRACY_USER, FITOCRACY_PASSWORD).score
require "beeminder" bee = Beeminder::User.new(BEEMINDER_TOKEN) goal = bee.goal("fitocracy") dp = Beeminder::Datapoint.new(value: score, comment: "Added automatically") goal.add(dp)