From d71be07332c7952562bffa71fd2a49b4c97e312a Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Sun, 13 Mar 2022 15:07:35 -0500 Subject: Add initial budget script --- budget-from-email.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 budget-from-email.py diff --git a/budget-from-email.py b/budget-from-email.py new file mode 100755 index 0000000..045cb59 --- /dev/null +++ b/budget-from-email.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3 + +import email_helper +import datetime +import subprocess +import requests +from config import config + +import sys +import os + +if not os.getenv("BUDGET_USERNAME") or not os.getenv("BUDGET_PASS"): + print("No credentials set") + sys.exit() + +merchant_map = { + "starbucks": ("starbucks", "restaurants", "coffee"), +} + +def get_chase_alert_emails(): + bodies = email_helper.filter_unread("subject", "transaction with", "body from subject") + for b in bodies: + #if b["from"] != "no-reply@alertsp.chase.com": + # continue + _, amount, _, _, merchant = b["subject"][5:].lower().split(" ", 4) + amount = amount[1:] + for key, values in merchant_map.items(): + if key in merchant: + where, category, subcategory = values + print(where, amount, category, subcategory, sep="\t") + payload = { + "username": os.getenv("BUDGET_USERNAME"), + "password": os.getenv("BUDGET_PASS"), + } + with requests.Session() as s: + p = s.post("https://budget.marks.kitchen/login", data=payload) + payload = { + "when": "", + "where": where, + "amount": amount, + "category": category, + "subcategory": subcategory, + } + p = s.post("https://budget.marks.kitchen/transaction", data=payload) + print(p.status_code) + +get_chase_alert_emails() -- cgit v1.2.3