-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: add method to get budgets #52
Conversation
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.
Thanks for writing this! I had just a couple comments.
monarchmoney/monarchmoney.py
Outdated
Get your budgets and correspond actual amounts from the account. | ||
|
||
:param start_date: the earliest date to get budget data from, in "yyyy-mm-dd" format (default: last month) | ||
:param end_date: the latest date to get budget data from, in "yyyy-mm-dd" format (default: next month) | ||
:param use_legacy_goals: Set True to return monthly budget set aside for goals (think no longer used) | ||
:param use_v2_goals: Set True to return monthly budget set aside for version 2 goals |
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.
minor: can we add a snippet here that explains that, if the start_date
and end_date
params aren't set, it will default to retrieving three months of budgets, starting with last month (according to today's date)? Assuming I read the code correctly. :)
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.
@grablair Updated docstring to clarify what the default values will be.
use_legacy_goals: Optional[bool] = False, | ||
use_v2_goals: Optional[bool] = True, |
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.
What happens if you both of these are set to True
or False
? Are those valid parameter combinations?
If a condition for validity of the API call is that use_legacy_goals != use_v2_goals
, I wonder if we can just simplify this to on use_legacy_goals
parameter that determines the values of both the parameters in the API call.
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.
@grablair This is the result from the query:
(use_legacy_goals=true, use_v2_goals=true): two lists returned. One list under dictionary key "goals" and another list under dictionary key "goalsV2". If you have no goals, the list will be empty.
(use_legacy_goals=false, use_v2_goals=false): no lists returned. No dictionary key called "goals" and "goalsV2" respectively.
So all combinations could be valid
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.
Great, thank you!
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.
Thanks, @Sean280ZX!
use_legacy_goals: Optional[bool] = False, | ||
use_v2_goals: Optional[bool] = True, |
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.
will it still work if someone sets both of these to True
?
last_month = today.month - 1 | ||
last_month_year = today.year | ||
first_day_of_last_month = 1 | ||
if last_month < 1: | ||
last_month_year -= 1 | ||
last_month = 12 | ||
variables["startDate"] = datetime( | ||
last_month_year, last_month, first_day_of_last_month | ||
).strftime("%Y-%m-%d") | ||
|
||
# Get the last day of next month | ||
next_month = today.month + 1 | ||
next_month_year = today.year | ||
if next_month > 12: | ||
next_month_year += 1 | ||
next_month = 1 | ||
last_day_of_next_month = calendar.monthrange(next_month_year, next_month)[1] | ||
variables["endDate"] = datetime( | ||
next_month_year, next_month, last_day_of_next_month | ||
).strftime("%Y-%m-%d") |
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.
use Python's timedelta
instead of computing these yourself:
# Get first day of last month
last_month_start = today - datetime.timedelta(weeks=4)
last_month.replace(day=1)
variables["startDate"] = last_month_start.strftime("%Y-%m-%d")
# Get the last day of the next month
next_month_end = today + datetime.timedelta(weeks=4)
next_month_end.replace(
day=calendar.monthrange(
next_month_end.year,
next_month_end.month
)[1]
)
variables["endDate"] = next_month_end.strftime("%Y-%m-%d")
This request adds the query for obtaining budgets data (same query as MonarchMoney "budget" section). Used same defaults as MonarchMoney where budget data will pull last month, current month, and next months budget data.
To test, run
main.py.
you will observe a newbudgets.json
file with the results of the query.