Skip to content

Instantly share code, notes, and snippets.

@anaisbetts
Created March 30, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anaisbetts/9877117 to your computer and use it in GitHub Desktop.
Save anaisbetts/9877117 to your computer and use it in GitHub Desktop.
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