Created
April 9, 2011 08:19
-
-
Save jasonmp85/911239 to your computer and use it in GitHub Desktop.
Quick-and-dirty script to fetch the latest bill from AT&T as a PDF.
This file contains hidden or 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 | |
# 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 [email protected] -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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.