-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from stenjo/ynabmodel
Ynabmodel
- Loading branch information
Showing
85 changed files
with
148 additions
and
15,801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
personal_api_settings.py | ||
.vscode/* | ||
*.csv | ||
ynab/models/__pycache__/* | ||
ynab/ynab/__pycache__/* | ||
ynab/__pycache__/* | ||
*/*/*/__pycache__/* | ||
*/__pycache__/* | ||
__pycache__/* | ||
api_settings.py | ||
*settings.py* | ||
sync_accounts.1.py | ||
bash_script.sh | ||
api_settings_temp.py | ||
api_settings.live.py | ||
.gitignore | ||
*/*.pyc | ||
*.pyc | ||
sync_accounts.log | ||
.coverage | ||
log/* | ||
*.log | ||
transacti* | ||
statement* | ||
workspace* | ||
secret* | ||
coverage.xml | ||
workspace.code-workspace | ||
log/*.json | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import datetime | ||
from pprint import pprint | ||
from ynab.Ynab import Ynab | ||
import api_settings | ||
|
||
# YNAB auth | ||
ynab = Ynab(api_settings.api_key, api_settings.budget_id) | ||
|
||
ynab_accounts = ynab.GetAccounts() | ||
|
||
pprint(ynab_accounts) | ||
|
||
today = datetime.date.today() | ||
endDate = today | ||
startDate = today - datetime.timedelta(80) # Last 8 days - unless changed in api_settings | ||
|
||
existing_transactions = ynab.GetTransactionsByAccount('9280f4d8-92c4-46a4-aba1-0cb41a92f85b', startDate) | ||
|
||
pprint(existing_transactions) | ||
yTrs = [] # Transactions to YNAB | ||
sTrns = ynab.SaveTransaction(today, -20000, '9280f4d8-92c4-46a4-aba1-0cb41a92f85b', 'Tesing memo', '46a47-aba1', 'Brukskonto', []) | ||
yTrs.append(sTrns) | ||
ynab.CreateTransactions(yTrs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,126 @@ | ||
import ynab | ||
from ynab.rest import ApiException | ||
import ynab_api | ||
from ynab_api.api import accounts_api, transactions_api | ||
from ynab_api.models import TransactionDetail, SaveTransaction, UpdateTransaction | ||
# from ynab_api import exceptions, models | ||
|
||
class Ynab: | ||
|
||
configuration = ynab.Configuration() | ||
|
||
def __init__(self, api_key, budgetId): | ||
self.budgetId = budgetId | ||
self.api_key = api_key | ||
|
||
# Configure API key authorization: bearer | ||
self.configuration.api_key['Authorization'] = api_key | ||
self.configuration.api_key_prefix['Authorization'] = 'Bearer' | ||
self.configuration = ynab_api.Configuration(host="https://api.youneedabudget.com/v1") | ||
self.configuration.api_key['bearer'] = self.api_key | ||
self.configuration.api_key_prefix['bearer'] = 'Bearer' | ||
|
||
# create an instance of the API class | ||
self.api_instance = ynab.TransactionsApi(ynab.ApiClient(self.configuration)) | ||
self.api_accounts = ynab.AccountsApi(ynab.ApiClient(self.configuration)) | ||
|
||
self.budgetId = budgetId | ||
# # create an instance of the API class | ||
self.api_client = ynab_api.ApiClient(self.configuration) | ||
self.accounts_instance = accounts_api.AccountsApi(self.api_client) | ||
self.transactions_instance = transactions_api.TransactionsApi(self.api_client) | ||
|
||
|
||
|
||
def GetAccounts(self): | ||
# Find ynab accounts | ||
# create an instance of the API class | ||
# with ynab_api.ApiClient(self.configuration) as api_client: | ||
# self.configuration = ynab_api.Configuration(host="https://api.youneedabudget.com/v1") | ||
# self.configuration.api_key['bearer'] = self.api_key | ||
# self.configuration.api_key_prefix['bearer'] = 'Bearer' | ||
|
||
|
||
# create an instance of the API class | ||
# self.api_client = ynab_api.ApiClient(self.configuration) | ||
# self.accounts_instance = accounts_api.AccountsApi(self.api_client) | ||
try: | ||
# Get existing accounts for the budget | ||
api_response = self.api_accounts.get_accounts(self.budgetId) | ||
except ApiException as e: | ||
api_response = self.accounts_instance.get_accounts(self.budgetId) | ||
except ynab_api.ApiException as e: | ||
print("Exception when calling AccountsApi->get_accounts: %s\n" % e) | ||
|
||
return api_response.data.accounts | ||
|
||
|
||
def GetTransactionsByAccount(self, accountId, fromDate): | ||
# Configure API key authorization: bearer | ||
# self.configuration = ynab_api.Configuration(host="https://api.youneedabudget.com/v1") | ||
# self.configuration.api_key['bearer'] = self.api_key | ||
# self.configuration.api_key_prefix['bearer'] = 'Bearer' | ||
|
||
|
||
# create an instance of the API class | ||
# self.api_client = ynab_api.ApiClient(self.configuration) | ||
# self.transactions_instance = transactions_api.TransactionsApi(self.api_client) | ||
try: | ||
# Get existing transactions that are Reserved in case they need to be updated | ||
api_response = self.api_instance.get_transactions_by_account(self.budgetId, accountId, since_date=fromDate) | ||
api_response = self.transactions_instance.get_transactions_by_account(self.budgetId, accountId, since_date=fromDate) | ||
|
||
except ApiException as e: | ||
except ynab_api.ApiException as e: | ||
print("Exception when calling AccountsApi->get_accounts: %s\n" % e) | ||
|
||
return api_response.data.transactions | ||
|
||
def CreateTransactions(self, transactionList): | ||
# create an instance of the API class | ||
# api_instance = self.transactions_instance.TransactionsApi(self.api_client) | ||
try: | ||
# Create new transaction | ||
api_response = self.api_instance.create_transaction(self.budgetId, {"transactions":transactionList}) | ||
except ApiException as e: | ||
api_response = self.transactions_instance.create_transaction(self.budgetId, {"transactions":transactionList}) | ||
except ynab_api.ApiException as e: | ||
print("Exception when calling TransactionsApi->create_transaction: %s\n" % e) | ||
|
||
def UpdateTransactions(self, transactionList): | ||
# create an instance of the API class | ||
# api_instance = transactions_api.TransactionsApi(self.api_client) | ||
try: | ||
# Update existing transactions | ||
api_response = self.api_instance.update_transactions(self.budgetId, {"transactions": transactionList}) | ||
except ApiException as e: | ||
api_response = self.transactions_instance.update_transactions(self.budgetId, {"transactions": transactionList}) | ||
except ynab_api.ApiException as e: | ||
print("Exception when calling TransactionsApi->update_transaction: %s\n" % e) | ||
|
||
def Transaction(self, tdate, tamount, accountId, tmemo, timportId): | ||
return ynab.TransactionDetail( | ||
def Transaction(self, tdate, tamount, accountId, tmemo, timportId, accountName, subtrans=[], transactionId = ''): | ||
# api_instance = accounts_api.TransactionsApi(self.api_client) | ||
return TransactionDetail( | ||
date=tdate, | ||
amount=tamount, | ||
cleared='uncleared', | ||
approved=False, | ||
account_id=accountId, | ||
account_name=accountName, | ||
memo=tmemo, | ||
import_id=timportId, | ||
subtransactions=subtrans, | ||
deleted=False, | ||
id = transactionId | ||
) | ||
|
||
def SaveTransaction(self, tdate, tamount, accountId, tmemo, timportId, accountName, subtrans=[], transactionId = ''): | ||
# api_instance = accounts_api.TransactionsApi(self.api_client) | ||
return SaveTransaction( | ||
date=tdate, | ||
amount=tamount, | ||
cleared='uncleared', | ||
approved=False, | ||
account_id=accountId, | ||
account_name=accountName, | ||
memo=tmemo, | ||
import_id=timportId | ||
import_id=timportId, | ||
subtransactions=subtrans, | ||
deleted=False, | ||
id = transactionId | ||
) | ||
|
||
def UpdateTransaction(self, transaction): | ||
return UpdateTransaction( | ||
date = transaction.date, | ||
amount = transaction.amount, | ||
cleared = transaction.cleared, | ||
approved = transaction.approved, | ||
account_id = transaction.account_id, | ||
account_name = transaction.account_name, | ||
memo = transaction.memo, | ||
import_id = transaction.import_id, | ||
subtransactions = transaction.subtransactions, | ||
deleted = transaction.deleted, | ||
id = transaction.id | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.