Finalized the this month script, which will be sent weekly via text to me and necessary parties. The last month and new_month_check transactions are also cleaned up and working. The next tasks are to sunset the import of moneyed as reading the actual-py docs, I found that I can do transactions.get_amount() which will return a decimal formatted number instead of needing to change the strings, etc. Will also need to clean up the files so they are more organized for public release.
This commit is contained in:
49
new_month_check_transactions.py
Normal file
49
new_month_check_transactions.py
Normal file
@ -0,0 +1,49 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user