public
Created

Quick-and-dirty script to fetch the latest bill from AT&T as a PDF.

  • Download Gist
bill_getter.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#!/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

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.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.