Skip to content

Instantly share code, notes, and snippets.

@s2t2
Forked from c-lliope/money.rb
Created January 12, 2016 19:26
Show Gist options
  • Save s2t2/df1b7cf965c8ef1cd687 to your computer and use it in GitHub Desktop.
Save s2t2/df1b7cf965c8ef1cd687 to your computer and use it in GitHub Desktop.
Reports on the status of your goals in Simple, and catches them up if necessary
require 'capybara/poltergeist'
require 'ruby-progressbar'
session = Capybara::Session.new(:poltergeist)
session.visit("https://bank.simple.com/signin")
session.fill_in("username", with: "USERNAME")
session.fill_in("password", with: "PASSWORD")
session.click_on("Sign in")
puts "Safe to spend: #{session.find('#sts-flag').text}"
session.click_link("Goals")
goals = session.all(".timeline-goal-container")
puts "#{goals.count} goals"
def print_goal_stats(session)
goal_name = session.find(".goal-column-title").text
current_amount = session.find(".goal-column-token").text.gsub('$', '').gsub(',', '').to_f
total_amount = session.find(".goal-column-total h6").text.gsub('$', '').gsub(',', '').to_f
puts "#{goal_name}: $#{current_amount} / $#{total_amount}"
bar = ProgressBar.create(starting_at: current_amount, total: total_amount)
bar.stop
end
goals.each do |goal|
puts
begin
goal.click
rescue
"could'nt click #{goal.inspect}"
end
print_goal_stats(session)
button = session.find("#goal-navbar button", text: "Catch up")
if button.disabled?
puts "Button is disabled"
else
previous_amount = session.find(".goal-column-token").text
button.click
current_amount = session.find(".goal-column-token").text
if previous_amount == current_amount
puts "All caught up!"
else
puts "#{previous_amount} -> #{current_amount}"
end
end
end
puts
session.click_on "Activity"
puts "Safe to spend: #{session.find('#sts-flag').text}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment