diff options
Diffstat (limited to 'budget-from-email.py')
-rwxr-xr-x | budget-from-email.py | 47 |
1 files changed, 47 insertions, 0 deletions
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() |