Automate Life > Banking

There was a time where I needed to login to multiple credit card, banking, and broker websites to find out where my money stands. It only became critical when Citi would send me a notification that some rando stole my details and used them to buy gas & shoes somewhere in crime-ridden Chicago. Otherwise, I’d simply assume everything was fine.

Now I have so many bots out there, that there are practicaly no surprises when it comes to my finances. The example Python script below uses Playwright to login to the sites for me and report back daily updates. All my bots ping a Slack channel so I can see how my world looks by simply going to one place. Combining them all together into a giant Transformer-like payday script, they automate paying my credit cards and balancing checking & savings accounts to the levels I set.

from playwright.sync_api import Playwright, sync_playwright
import time

def run(playwright):
    browser = playwright.firefox.launch(headless=True)
    context = browser.new_context()
    page = context.new_page()
    try:
        page.goto("https://www.citi.com/")
        page.get_by_role("textbox", name="User ID").click()
        page.get_by_role("textbox", name="User ID").fill("USER")
        time.sleep(3)
        page.get_by_role("textbox", name="Password").click()
        page.get_by_role("textbox", name="Password").fill("PASSWORD")
        page.get_by_role("textbox", name="Password").press("Enter")
        time.sleep(10)
        element = page.locator("div.current-balance.negative-balance")
        text_content = element.inner_text()
        owed_amount = float(text_content.replace("$", "").replace(",", ""))
        return owed_amount
    except Exception as e:
        print(f"An error occurred: {e}")
        return None
    finally:
        context.close()
        browser.close()

with sync_playwright() as playwright:
    run(playwright)

To get Playwright running on your system, you’ll need to:

pip install pytest-playwright;
playwright install;

You’ll also need to install browser engines via their documentation. I’m a Firefox user, so that’s an obvious no-brainer as to what engine I prefer. It’s incredibly rare that something out there is Chrome only.

If you want to hit up a Slack webhook notification, use the following:

from urllib import request
import json

def send_message_to_slack(text):
    post = {"text": "{0}".format(text)}
    try:
	    json_data = json.dumps(post)
	    req = request.Request("https://hooks.slack.com/services/API_KEY",
data=json_data.encode('ascii'),headers={'Content-Type': 'application/json'}) 
	    resp = request.urlopen(req)
    except Exception as em:
	    print("EXCEPTION: " + str(em))

You can automate site scraping to an amazing degree when it can all be scripted in Python. I also have a bot that performs Bing web searches based on a randomized top 500 Wikipedia entries for the day. This allows me a decent return on their rewards program. That bot also pings me the details in slack - obviously.

Previous: The Negotiator Next: King of California