public
Last active

Ruby script to retrieve and display Comcast data usage. See http://wonko.com/post/ruby-script-to-display-comcast-data-usage

  • Download Gist
capmon.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/env ruby
 
require 'rubygems'
require 'mechanize'
 
URL_LOGIN = 'https://login.comcast.net/login?continue=https://login.comcast.net/account'
URL_USERS = 'https://customer.comcast.com/Secure/Users.aspx'
 
abort "Usage: #{$0} <username> <password>" unless ARGV.length == 2
 
agent = Mechanize.new
 
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_LOGIN)
 
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)
 
users_page = agent.get(URL_USERS)
usage_text = users_page.search("div[@class='usage-graph-legend']").first.content
 
puts usage_text.strip

I have made some updates in my fork that gets this code running again, https://gist.github.com/1174897

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.