-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathynabdemo.py
98 lines (83 loc) · 3.87 KB
/
ynabdemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import json
import datetime
import ynab_api
from ynab_api.api import categories_api, transactions_api
from ynab_api.model.save_category_response import SaveCategoryResponse
from ynab_api.model.save_month_category_wrapper import SaveMonthCategoryWrapper
from ynab_api.model.save_month_category import SaveMonthCategory
from pprint import pprint
import ynab_api
from pprint import pprint
from ynab_api.api import accounts_api
with open('secrets.json') as f:
secrets = json.load(f)
budget_id = secrets['budget_id']
api_key = secrets['api_key']
configuration = ynab_api.Configuration(
host="https://api.youneedabudget.com/v1")
configuration.api_key['bearer'] = api_key
configuration.api_key_prefix['bearer'] = 'Bearer'
def get_accounts():
with ynab_api.ApiClient(configuration) as api_client:
api_instance = accounts_api.AccountsApi(api_client)
try:
ar = api_response = api_instance.get_accounts(budget_id)
pprint(api_response)
except ynab_api.ApiException as e:
print("Exception: %s\n" % e)
def get_categories():
with ynab_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = categories_api.CategoriesApi(api_client)
month = datetime.date.today().isoformat(
) # date | The budget month in ISO format (e.g. 2016-12-01) (\"current\" can also be used to specify the current calendar month (UTC))
category_id = "travel" # str | The id of the category
data = SaveMonthCategoryWrapper(
category=SaveMonthCategory(budgeted=1, ),
) # SaveMonthCategoryWrapper | The category to update. Only `budgeted` amount can be updated and any other fields specified will be ignored.
# example passing only required values which don't have defaults set
try:
# Update a category for a specific month
ar = api_response = api_instance.get_categories(budget_id)
pprint(api_response)
except ynab_api.ApiException as e:
print(
"Exception when calling CategoriesApi->update_month_category: %s\n"
% e)
def get_transactions():
with ynab_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = transactions_api.TransactionsApi(api_client)
try:
# Update a category for a specific month
ar = api_response = api_instance.get_transactions(budget_id)
pprint(api_response)
except ynab_api.ApiException as e:
print(
"Exception when calling CategoriesApi->update_month_category: %s\n"
% e)
def update_budget():
with ynab_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = categories_api.CategoriesApi(api_client)
month = datetime.date.today().isoformat(
) # date | The budget month in ISO format (e.g. 2016-12-01) (\"current\" can also be used to specify the current calendar month (UTC))
#month = "2021-10-07"
category_id = "93cb7fbb-bd49-4c0b-8580-754f29250dac"
data = SaveMonthCategoryWrapper(
category=SaveMonthCategory(budgeted=1, ),
) # SaveMonthCategoryWrapper | The category to update. Only `budgeted` amount can be updated and any other fields specified will be ignored.
# example passing only required values which don't have defaults set
try:
# Update a category for a specific month
api_response = api_instance.update_month_category(
budget_id, month, category_id, data)
pprint(api_response)
except ynab_api.ApiException as e:
print(
"Exception when calling CategoriesApi->update_month_category: %s\n"
% e)
get_transactions()
get_categories()
get_accounts()
#update_budget()