forked from hammem/monarchmoney
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
98 lines (78 loc) · 3.07 KB
/
main.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import asyncio
import os
import json
from monarchmoney import MonarchMoney
_SESSION_FILE_ = ".mm/mm_session.pickle"
def main() -> None:
# Use session file
mm = MonarchMoney(session_file=_SESSION_FILE_)
asyncio.run(mm.interactive_login())
# Subscription details
subs = asyncio.run(mm.get_subscription_details())
print(subs)
# Accounts
accounts = asyncio.run(mm.get_accounts())
with open("data.json", "w") as outfile:
json.dump(accounts, outfile)
# Institutions
institutions = asyncio.run(mm.get_institutions())
with open("institutions.json", "w") as outfile:
json.dump(institutions, outfile)
# Budgets
budgets = asyncio.run(mm.get_budgets())
with open("budgets.json", "w") as outfile:
json.dump(budgets, outfile)
# Transactions summary
transactions_summary = asyncio.run(mm.get_transactions_summary())
with open("transactions_summary.json", "w") as outfile:
json.dump(transactions_summary, outfile)
# # Transaction categories
categories = asyncio.run(mm.get_transaction_categories())
with open("categories.json", "w") as outfile:
json.dump(categories, outfile)
income_categories = dict()
for c in categories.get("categories"):
if c.get("group").get("type") == "income":
print(
f'{c.get("group").get("type")} - {c.get("group").get("name")} - {c.get("name")}'
)
income_categories[c.get("name")] = 0
expense_category_groups = dict()
for c in categories.get("categories"):
if c.get("group").get("type") == "expense":
print(
f'{c.get("group").get("type")} - {c.get("group").get("name")} - {c.get("name")}'
)
expense_category_groups[c.get("group").get("name")] = 0
# Transactions
transactions = asyncio.run(mm.get_transactions(limit=10))
with open("transactions.json", "w") as outfile:
json.dump(transactions, outfile)
# Cashflow
cashflow = asyncio.run(
mm.get_cashflow(start_date="2023-10-01", end_date="2023-10-31")
)
with open("cashflow.json", "w") as outfile:
json.dump(cashflow, outfile)
for c in cashflow.get("summary"):
print(
f'Income: {c.get("summary").get("sumIncome")} '
f'Expense: {c.get("summary").get("sumExpense")} '
f'Savings: {c.get("summary").get("savings")} '
f'({c.get("summary").get("savingsRate"):.0%})'
)
for c in cashflow.get("byCategory"):
if c.get("groupBy").get("category").get("group").get("type") == "income":
income_categories[c.get("groupBy").get("category").get("name")] += c.get(
"summary"
).get("sum")
print()
for c in cashflow.get("byCategoryGroup"):
if c.get("groupBy").get("categoryGroup").get("type") == "expense":
expense_category_groups[
c.get("groupBy").get("categoryGroup").get("name")
] += c.get("summary").get("sum")
print(income_categories)
print()
print(expense_category_groups)
main()