Skip to content
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

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

Sean280ZX
Copy link
Contributor

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 new budgets.json file with the results of the query.

Copy link
Collaborator

@grablair grablair left a 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. ☺️

Comment on lines 401 to 406
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
Copy link
Collaborator

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. :)

Copy link
Contributor Author

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.

Comment on lines +397 to +398
use_legacy_goals: Optional[bool] = False,
use_v2_goals: Optional[bool] = True,
Copy link
Collaborator

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.

Copy link
Contributor Author

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you!

Copy link
Owner

@hammem hammem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Sean280ZX!

Comment on lines +397 to +398
use_legacy_goals: Optional[bool] = False,
use_v2_goals: Optional[bool] = True,
Copy link
Owner

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?

Comment on lines +590 to +609
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")
Copy link
Owner

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")

@hammem hammem merged commit 24add1d into hammem:main Jan 4, 2024
1 check failed
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.

3 participants