Git Product home page Git Product logo

mint_notifier's Introduction

Mint Scraper And Notifier

A script that serves two functions.

  1. Scrapes Mint for daily spend and income
  2. Sends me a text with my aggregrate and itemized spend/income every night at 10PM

Rationale

I wanted to get better insight into my daily spending. There are many spending apps out there, but they offer more features than I want and lack the simple notifications I do want. This began as a weekend hack project that eventually grew into a more robust app driven by Plaid.

Overview

This solution is hacky! And I love hacky things :)

This is a general overview of how the script interacts with Mint

  1. The script simulates a browser with Capybara/Selenium
  2. The script visits the Mint homepage
  3. The script logs in with username/password
  4. Mint will then text you a login token to your phone
  5. The script finds the Mint text by looking through your local iMessage chats
  6. The script inputs the login token and completes authentication
  7. The script navigates to the transactions page
  8. The script collects all transactions for the current date
  9. The script creates a summary message of the transactions and uses Twilio to send you the summary message

Requirements

  • Ruby and Bundle
  • Mint Account
  • Twilio Account
  • Macbook, iPhone, and a shared iMessage account between the two devices

Building

  1. Clone the repo
$ git clone XXXXXXXXXXXXX
  1. Install gems
$ bundle i
  1. Download both the chromedriver and geckodriver, and put them somewhere in your PATH. At the time of writing this doc, I'm using version 2.46 of the chromedriver but you can find the latest version here.

    If you want to run this app without making any changes, add these two executables to the directory $HOME/.chromedriver. Then add that directory to your PATH.

  2. Copy the env template and fill it out with your values

$ cp .env.template .env

Running

There are two main ways to run this program.

Run Manually

This command will immediately send a text with today's spend/income. This is useful to test that everything is setup correctly.

$ bundle exec ruby main.rb

Run Periodically

The real reason I built this script was to receive a text every night with my spend/income. To do that I used cron.

When a script is run via cron it doesn't have the same PATH or other environment variables as when you are running the script yourself. For example, if I used this cron command...

0 0 22 * * bundle exec ruby /Users/codemang/Personal/mint/main.rb

It would use the system ruby. This would break for me, because I use a different version of ruby when developing. Gems that have been installed are scoped to the ruby version, so my system ruby would not find the required gems for this script. It would also likely complain that it couldn't find the chromedriver executable.

To solve this problem, I created a bash script main.sh which would first configure the environment. The three things that needed to be done were...

  1. Use the correct ruby build. I use chruby to manage my ruby versions so you can see calls to their startup scripts.

  2. Add chromedriver to the path

  3. Call the script

# Add chromedriver to path
PATH=/Users/codemang/.chromedriver:$PATH

# Switch to using chruby ruby so gems can be found
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

# Call the script
cd "$( dirname "$0" )"
bundle exec ruby main.rb schedule

Now I can add this to my crontab and the script will run successfully.

0 0 22 * * /Users/codemang/Personal/mint_notifier/main.sh

Lastly, since I only want to receive one text at 10PM, I could try to setup my cron as above. But what if I had my computer closed? The script wouldn't run and no text would be sent for the day.

To make this more resilient, I run the script every five minutes and track when texts have been sent to avoid double texting. If my computer is closed at 10PM but I open at 11PM, it will send the text then. Additionally, if my computer has been closed for multiple days, it will send texts for those missed days.

To enable this functionality, you just have to pass in schedule as a command line argument, which you can see in main.sh. The final cron command is...

*/5 * * * * /Users/codemang/Personal/mint_notifier/main.sh

Viewing The Browser

If you want to view the browser as it is being automated, just call the script with VISIBLE_BROWSER=true

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.