Create a gist now

Instantly share code, notes, and snippets.

Quick-and-dirty script to fetch the latest bill from AT&T as a PDF.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'optparse'
require 'ostruct'
require 'mechanize'
options = OpenStruct.new
parser = OptionParser.new do |p|
p.banner = 'Usage: bill_getter [OPTIONS]'
p.separator 'Example: bill_getter -u user@att.net -p secret'
p.separator ''
p.separator 'Getter options:'
p.on('-u', '--user USERNAME',
'Login using the user USERNAME') do |user|
options.user = user
end
p.on('-p', '--password PASSWORD',
'Authenticate with PASSWORD') do |pw|
options.pw = pw
end
p.on('-f', '--filename FILENAME',
'Save PDF to FILENAME',
'(default stdout)') do |filename|
options.filename = File.expand_path filename
end
p.separator ''
p.separator 'Miscellaneous:'
p.on_tail('-h', '--help', 'Show this message') do
puts p
exit
end
end
begin
parser.parse! ARGV
raise ArgumentError unless options.user && options.pw
rescue
puts parser
exit
end
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get 'http://www.att.com/uversecentral'
form = page.form 'loginActionForm'
form.wireless_num = options.user
form.accountType = 'UVERSE'
form.pass = options.pw
form.customerType = 'UVERSE'
agent.submit form
pdf = agent.get_file 'https://www.att.com/view/uverse_printer_friendly.action'
if options.filename
File.open(options.filename, 'w') {|f| f.write pdf}
else
puts pdf
end
@jasonmp85
Owner

Usage

Just run bill_getter.rb --help and you'll see how to use it. Can either output to standard out or a file. Doesn't do any error checking, and will probably break whenever AT&T next screws with their webpage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment