1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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()
|