Skip to content

Instantly share code, notes, and snippets.

@bhattisatish
Forked from m0tive/gist:1884821
Created February 22, 2012 14:15
Show Gist options
  • Save bhattisatish/1885304 to your computer and use it in GitHub Desktop.
Save bhattisatish/1885304 to your computer and use it in GitHub Desktop.
export google history
require 'mechanize'
require 'logger'
require 'date'
## Call:
## $ ruby export.rb <gmail> <password>
# https://www.google.com/history/lookup?hl=en&month=11&day=04&yr=2008&output=rss&num=9999
agent = Mechanize.new do |a|
a.user_agent_alias = 'Linux Mozilla'
a.log = Logger.new(STDOUT)
#a.ssl_version = 'SSLv3'
a.ca_file = 'cacert.pem' # get this from http://curl.haxx.se/ca/cacert.pem
end
login_page = agent.get('http://www.google.com/history')
success_page = login_page.form_with(:action => 'https://accounts.google.com/ServiceLoginAuth') do |f|
f.Email = ARGV[0]
f.Passwd = ARGV[1]
end.click_button
feedURL = 'http://www.google.com/history/lookup?output=rss&num=9999'
lastFile = ''
loop do
rss = agent.get(feedURL)
rssXml = Nokogiri::XML(rss.body)
lastItem = rssXml.xpath('//pubDate').last
d = DateTime.parse(lastItem.inner_text)
thisFile = "#{d.year}_#{d.month}_#{d.day}.xml"
break if thisFile == lastFile
rss.save(thisFile)
lastFile = thisFile
feedURL = "http://www.google.com/history/lookup?output=rss&num=9999&month=#{d.month}&day=#{d.day}&yr=#{d.year}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment