-
-
Notifications
You must be signed in to change notification settings - Fork 94
Improve upload account balance history #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
9b8c69b
813adca
1593b90
9bf0010
cbff400
1d2eb40
a4c614c
76ebcde
00c6760
7ad7961
967447b
ad421a8
d6f5180
14beaf3
1d07ae0
8b37717
76d25b2
e7acd66
1fe7987
ee959a3
7f68c9c
44711ad
4e2d624
53b6abc
86a0311
ee41dc6
9394a97
508f9bf
2d4f1b4
89a9ce9
b6bbf50
d97de7f
34e440d
b6732d6
a1703a3
d317b9a
3989f3e
147b1aa
88e3dc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,7 @@ As of writing this README, the following methods are supported: | |
| - `set_budget_amount` - sets a budget's value to the given amount (date allowed, will only apply to month specified by default). A zero amount value will "unset" or "clear" the budget for the given category. | ||
| - `create_manual_account` - creates a new manual account | ||
| - `delete_account` - deletes an account by the provided account id | ||
| - `upload_account_balance_history` - uploads account history csv file for a given account | ||
| - `upload_and_parse_balance_history` - uploads and parses account history csv file for a given account | ||
|
||
|
|
||
| # Contributing | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2392,14 +2392,54 @@ async def set_budget_amount( | |||||
| graphql_query=query, | ||||||
| ) | ||||||
|
|
||||||
| async def upload_and_parse_balance_history( | ||||||
| self, | ||||||
| account_id: str, | ||||||
| csv_content, | ||||||
|
||||||
| timeout: int = 300, | ||||||
| delay: int = 10, | ||||||
|
||||||
| ) -> bool: | ||||||
| """ | ||||||
| Uploads and parses the balance history, updating the account balance on monarch money | ||||||
|
|
||||||
| :param account_id: The account ID to apply the history to. | ||||||
| :param csv_content: CSV representation of the balance history. Headers are Date, Amount, and Account Name. | ||||||
|
||||||
| :param timeout: The number of seconds to wait before timing out | ||||||
| :param delay: The number of seconds to wait for each check on whether parsing is completed | ||||||
| """ | ||||||
|
|
||||||
| session_key = await self.upload_account_balance_history( | ||||||
| account_id=account_id, csv_content=csv_content | ||||||
| ) | ||||||
|
|
||||||
| response = await self.parse_upload_balance_history_session( | ||||||
| session_key=session_key | ||||||
| ) | ||||||
|
|
||||||
| is_completed = ( | ||||||
| response["parseBalanceHistory"]["uploadBalanceHistorySession"]["status"] | ||||||
| == "completed" | ||||||
| ) | ||||||
|
|
||||||
| start = time.time() | ||||||
|
|
||||||
| while not is_completed and (time.time() <= (start + timeout)): | ||||||
| await asyncio.sleep(delay) | ||||||
|
|
||||||
| is_completed = (await self.get_upload_balance_history_session(session_key))[ | ||||||
| "uploadBalanceHistorySession" | ||||||
| ]["status"] | ||||||
|
||||||
|
|
||||||
| return is_completed | ||||||
|
|
||||||
| async def upload_account_balance_history( | ||||||
| self, account_id: str, csv_content: str | ||||||
| ) -> None: | ||||||
| ) -> str: | ||||||
| """ | ||||||
| Uploads the account balance history csv for a given account. | ||||||
| Uploads the account balance history CSV for a specified account. | ||||||
|
|
||||||
| :param account_id: The account ID to apply the history to. | ||||||
| :param csv_content: CSV representation of the balance history. | ||||||
| :param csv_content: CSV representation of the balance history. Headers: Date, Amount, and Account Name. | ||||||
|
||||||
| """ | ||||||
| if not account_id or not csv_content: | ||||||
| raise RequestFailedException("account_id and csv_content cannot be empty") | ||||||
|
|
@@ -2417,6 +2457,71 @@ async def upload_account_balance_history( | |||||
| if resp.status != 200: | ||||||
| raise RequestFailedException(f"HTTP Code {resp.status}: {resp.reason}") | ||||||
|
|
||||||
| response = await resp.json() | ||||||
| session_key = response["session_key"] | ||||||
| return session_key | ||||||
|
||||||
|
|
||||||
| async def parse_upload_balance_history_session(self, session_key: str) -> dict: | ||||||
|
||||||
| async def parse_upload_balance_history_session(self, session_key: str) -> dict: | |
| async def initiate_upload_balance_history_session(self, session_key: str) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for consistency with similar methods in this API
| async def get_upload_balance_history_session(self, session_key: str): | |
| async def is_upload_balance_history_complete(self, session_key: str) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please pull this branch off of your other commits in the other PR, so it doesn't accidentally introduce those changes simultaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!