50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
from actual import Actual, Transactions
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from actual.queries import get_transactions
|
|
from datetime import datetime, timedelta
|
|
from moneyed import Money, USD
|
|
from moneyed.l10n import format_money
|
|
from last_month import compare_months
|
|
import last_month
|
|
from dateutil.relativedelta import relativedelta
|
|
import json
|
|
import re
|
|
import pprint
|
|
|
|
pp=pprint.PrettyPrinter(indent=4, sort_dicts=False)
|
|
load_dotenv()
|
|
THISMONTH = datetime.now()
|
|
# datestring= "2025-08-06 13:57:57"
|
|
# format = '%Y-%m-%d %H:%M:%S'
|
|
# THISMONTH = datetime.strptime(datestring, format)
|
|
MONTHMINUSONE = THISMONTH - relativedelta(months=1)
|
|
MONTHMINUSTWO = THISMONTH - relativedelta(months=2)
|
|
ONBUDGETACCOUNTS = os.getenv('ONBUDGETACCOUNTS').split()
|
|
|
|
def main(actual, month):
|
|
accounts_with_curr_month = 0
|
|
monthdaydate = datetime.strftime(month, "%Y%m")
|
|
print(monthdaydate)
|
|
first_day_month = month.replace(day=1)
|
|
for account in ONBUDGETACCOUNTS:
|
|
latest_trans = get_transactions(actual.session, account=account, start_date=first_day_month)
|
|
# for acctrans in latest_trans:
|
|
if f"date={monthdaydate}" in str(latest_trans):# and not run_compare_months:
|
|
accounts_with_curr_month += 1
|
|
if accounts_with_curr_month == 3:
|
|
print("Hold onto your butts! All 3 accounts have this month's data!")
|
|
last_month.compare_months(actual)
|
|
else:
|
|
print(f"No current month transactions for {account}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with Actual(
|
|
base_url=os.getenv('BASEURL'),
|
|
password=os.getenv('PASSWORD'),
|
|
encryption_password=None,
|
|
file=os.getenv('FILE')
|
|
) as actual:
|
|
main(actual, THISMONTH)
|