require 'rubygems' require 'garb' # http://github.com/vigetlabs/garb/ require 'sparklines' # http://github.com/topfunky/sparklines Garb::Session.login('analytics@email.com', 'password') site = Garb::Profile.all.first days = [] length = 86400 puts "Generating graph of hits on #{site.title} homepage over last month" 30.times do |day| r = Garb::Report.new(site) r.metrics << :pageviews r.dimensions << :request_uri r.filters << {:request_uri.eql => '/'} r.start_date = Time.now - (length*day) r.end_date = Time.now - (length*(day-1)) days << r.all.first.pageviews.to_i end graph = Sparklines.plot(days, :type => 'smooth', :height => 20, :step => 1, :line_color => '#0080FF') graph_file = File.new("graph.jpg", "w") graph_file.write(graph) graph_file.close