Skip to content

Fix upload account balance history#136

Open
benjamindimant wants to merge 3 commits intohammem:mainfrom
benjamindimant:upload-balance-history-csv
Open

Fix upload account balance history#136
benjamindimant wants to merge 3 commits intohammem:mainfrom
benjamindimant:upload-balance-history-csv

Conversation

@benjamindimant
Copy link

The implementation using aiohttp FormData was not functioning as expected. This builds on the work of @CalvinChanCan and @hammem to implement this feature functionally.

To restate @CalvinChanCan's method described in #():

This PR improves on the upload account balance history.

The method upload_account_balance_history only uploads the CSV file but does not update the balance in Monarch Money.

A new method parse_upload_balance_history_session is added to parse the csv file which would cause an update to the account balance history.

Another new method get_upload_balance_history_session is added to check the status of whether the parsing is still processing or completed.

Finally upload_and_parse_balance_history uses these 3 methods together to upload and parse the account balance history so that it shows up in Monarch Money.

An example use case would be:

mm = MonarchMoney()
await mm.interactive_login()

# Get the account ID
accounts = await mm.get_accounts()
account = next((acc for acc in accounts['accounts'] if acc['displayName'] == "Bank Balance"), None)

# Load the target CSV and convert it into a list of BalanceHistoryRow
csv_file_path = "balance.csv"
balance_df = pd.read_csv(csv_file_path)
balance_history_rows = [
    BalanceHistoryRow(
        date=pd.to_datetime(row["Date"]),
        amount=row["Amount"],
        account_name=row["Account Name"]
    )
    for index, row in balance_df.iterrows()
]

await mm.upload_account_balance_history(account["id"], balance_history_rows)

@benjamindimant benjamindimant changed the title Use MultipartWriter instead of FormData due to CSV processing issues Fix upload account balance history Feb 13, 2025
@CFarzaneh
Copy link

Just checked out and confirmed working. Can we get this PR merged soon @hammem? The previous PR for this change was opened a year ago and never merged. I depend on upload_account_balance_history and it's been broken in main for over a year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants