-
-
Save ianlevesque/1184738 to your computer and use it in GitHub Desktop.
Ruby script to retrieve and display Comcast data usage. See http://www.128bitstudios.com/2011/08/27/comcast-data-usage-put-a-fork-in-it/
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mechanize' | |
URL_PRELOADER = 'https://customer.comcast.com/Secure/Preload.aspx?backTo=%2fSecure%2fUsers.aspx&preload=true' | |
URL_USERS = 'https://customer.comcast.com/Secure/Users.aspx' | |
URL_ACCOUNT = 'https://customer.comcast.com/Secure/Account.aspx' | |
abort "Usage: #{$0} <username> <password>" unless ARGV.length == 2 | |
agent = Mechanize.new | |
agent = Mechanize.new { |agent| | |
agent.follow_meta_refresh = true | |
agent.redirect_ok = true | |
agent.user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6' | |
} | |
login_page = agent.get(URL_USERS) | |
login_form = login_page.form_with(:name => 'signin') | |
login_form.user = ARGV[0] | |
login_form.passwd = ARGV[1] | |
redirect_page = agent.submit(login_form) | |
redirect_form = redirect_page.form_with(:name => 'redir') | |
abort 'Error: Login failed' unless redirect_form | |
account_page = agent.submit(redirect_form, redirect_form.buttons.first) | |
agent.get(URL_PRELOADER) | |
users_page = agent.get(URL_USERS) | |
usage_text = users_page.search(".usage-graph-legend").text | |
puts usage_text.strip | |
users_page = agent.get(URL_ACCOUNT) | |
date_range = users_page.search('//h3').select { |tag| tag.text =~ /Current Bill/ }.first | |
date_range_text = date_range.search('//small').text | |
puts date_range_text.strip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment