Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
Last active November 24, 2023 06:12
Show Gist options
  • Save carymrobbins/6302800 to your computer and use it in GitHub Desktop.
Save carymrobbins/6302800 to your computer and use it in GitHub Desktop.
Wells Fargo Automation
#!/usr/bin/env ruby
require 'io/console'
require 'mechanize'
agent = Mechanize.new
# http://curl.haxx.se/ca/cacert.pem
agent.ca_file = 'cacert.pem'
puts 'Connecting to Wells Fargo...'
page = agent.get 'https://wellsfargo.com'
puts 'Enter your credentials (the characters will not show)'
puts 'Username:'
userid = STDIN.noecho(&:gets).strip
puts 'Password:'
password = STDIN.noecho(&:gets).strip
begin
puts 'Signing in...'
form = page.form 'signon'
form.userid = userid
form.password = password
agent.submit form
page = agent.get 'https://online.wellsfargo.com/das/cgi-bin/session.cgi?screenid=SIGNON_PORTAL_PAUSE'
cash = page.search '//table[@id="cash"]'
strip = lambda{ |x| x.to_s.strip }
# Getting first text element to avoid text after <span>
title_list = cash.search('//tbody/tr/th/a/text()[1]').map &strip
balance_list = cash.search('//tbody/tr/td/a/text()').map &strip
balances = Hash[title_list.zip balance_list]
max_length = title_list.map(&:length).max
append_spaces = lambda{ |x| x + ' '*(max_length - x.length) }
# Table heading
puts
puts "#{append_spaces.call 'Account'} | Balance"
puts '-'*max_length + '-+' + '-'*10
# Table rows
balances.each do |k, v|
puts "#{append_spaces.call k} | #{v}"
end
# This part is incomplete...trying to download the activity file.
page = agent.click(page.link_with(text: /Account Activity/))
page = agent.click(page.link_with(text: /Download Activity/))
form = page.form 'DownloadFormBean'
form.radiobutton_with(name: /commaDelimited/).check
agent.submit form
ensure
puts
puts 'Signing out...'
agent.get 'https://online.wellsfargo.com/das/channel/signoff'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment