Created
March 30, 2014 18:08
-
-
Save anaisbetts/9877117 to your computer and use it in GitHub Desktop.
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 'active_support' | |
require 'active_support/time' | |
require 'active_support/core_ext' | |
require 'net/http' | |
require 'mechanize' | |
a = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } | |
a.get('http://www.loseit.com') do |p| | |
login = a.click(p.link_with(:text => "Sign In")) | |
logged_in_page = login.form_with(:action => "/") do |f| | |
f.username = "email@example.com" | |
f.password = "omgsekrit" | |
end.click_button | |
date = Time.now | |
start = date - 1.year - 3.months | |
## NB: /export expects its timestamps to be Unix epochs multiplied by 1000 | |
while date >= start do | |
puts "Downloading #{date.iso8601}..." | |
a.download "http://www.loseit.com/export/weekly?date=#{date.to_i * 1000}", "#{date.iso8601}.csv" | |
date = date - 1.week | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment