Skip to content

Instantly share code, notes, and snippets.

@notjosh
Created November 19, 2011 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notjosh/1379181 to your computer and use it in GitHub Desktop.
Save notjosh/1379181 to your computer and use it in GitHub Desktop.
ABN Amro credit card balance checker
#! /usr/bin/env ruby
# Password can be fetched from Keychain
# Password should be stored with the same username, and application name 'abnamro-credit-card'
HOST = 'https://creditcards.abnamro.nl'
LOGIN_URL = HOST + '/ABN_AMRO_Consumer/Login.do'
LOGIN_POST_URL = HOST + '/ABN_AMRO_Consumer/ProcessLogin.do'
ENGLISH_URL = HOST + '/ABN_AMRO_Consumer/ChangeLanguage.do?localeID=English&locationID=Transactions'
USERNAME = 'your.username'
PASSWORD = nil
require 'rubygems'
require 'mechanize'
# keychain
# blog post: http://blog.slashpoundbang.com/post/1521530410/accessing-the-os-x-keychain-from-ruby
class KeyChain
def self.method_missing(meth, *args)
run args.unshift(meth)
end
def self.find_generic_password(*args)
output = quiet args.unshift('find-generic-password', '-g')
output[/^password: "(.*)"$/, 1]
end
private
def self.run(*args)
`security #{args.join(' ')}`
end
def self.quiet(*args)
run args.unshift('2>&1 >/dev/null')
end
end
password = PASSWORD
if nil == password
# try to access keychain to recover password
password = KeyChain.find_generic_password '-s', 'abnamro-credit-card', '-a', '"joshua.may"'
end
abort 'ERROR: Password cannot be retrieved from keychain!' if password.nil?
agent = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
login_page = agent.get(LOGIN_URL)
login_form = login_page.form('logonForm')
login_form.username = USERNAME
login_form.password = password
account_page = agent.submit(login_form)
english_page = agent.get(ENGLISH_URL)
english_page.search('table.subTile').search('td.normaltext').search('tr').map { |tr|
key = tr.search('td')[0].text
value = tr.search('td')[1].text
puts "#{key}: #{value}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment