Created
July 17, 2012 19:11
-
-
Save rossmeissl/3131346 to your computer and use it in GitHub Desktop.
Sparkwire
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 'mechanize' | |
require 'logger' | |
require 'uri' | |
agent = Mechanize.new | |
agent.follow_meta_refresh = :always | |
agent.log = Logger.new 'mech.log' | |
agent.user_agent_alias = 'Mac FireFox' | |
puts 'Initialize the session by loading the login form' | |
agent.get 'https://www.pge.com/myenergyweb/appmanager/pge/customer' | |
puts 'Log in to PG&E' | |
page = agent.post 'https://www.pge.com/eum/login', 'USER' => 'foo', 'PASSWORD' => 'bar' | |
puts 'Click the link to Opower' | |
page = page.link_with(:text => 'My Usage').click | |
puts 'Continue the PG&E-side SSO process' | |
page = agent.submit page.forms.first, page.forms.first.buttons.first | |
puts 'Continue the Opower-side SSO process' | |
page = agent.submit page.forms.first, page.forms.first.buttons.first | |
puts 'Downloading all data' | |
page = page.link_with(:href => %r{export-dialog}).click | |
form = page.forms.first | |
form.radiobuttons_with(:name => 'exportFormat').last.check | |
form.from = '04/11/2012' | |
form.to = '05/11/2012' | |
agent.submit(form, form.buttons.first).save 'powa.zip' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment