Fix YNAB created transactions count
This commit is contained in:
parent
6bc72468de
commit
01e0d481b6
1 changed files with 10 additions and 2 deletions
|
@ -39,15 +39,23 @@ def push_transactions(transactions, account):
|
||||||
url = f"{BASE_URL}/budgets/{budget_id}/transactions"
|
url = f"{BASE_URL}/budgets/{budget_id}/transactions"
|
||||||
for transaction in transactions:
|
for transaction in transactions:
|
||||||
transaction["account_id"] = section["account"]
|
transaction["account_id"] = section["account"]
|
||||||
|
|
||||||
data = {"transactions": transactions}
|
data = {"transactions": transactions}
|
||||||
token = section["token"]
|
token = section["token"]
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
|
||||||
res = requests.post(url, json=data, headers=headers)
|
res = requests.post(url, json=data, headers=headers)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
data = res.json()["data"]
|
data = res.json()["data"]
|
||||||
created = data["transactions"]
|
|
||||||
duplicates = data["duplicate_import_ids"]
|
created = set()
|
||||||
|
for transaction in data["transactions"]:
|
||||||
|
matched_id = transaction["matched_transaction_id"]
|
||||||
|
if not matched_id or matched_id not in created:
|
||||||
|
created.add(transaction["id"])
|
||||||
click.secho(f"{len(created)} transactions created in YNAB.", fg="green", bold=True)
|
click.secho(f"{len(created)} transactions created in YNAB.", fg="green", bold=True)
|
||||||
|
|
||||||
|
duplicates = data["duplicate_import_ids"]
|
||||||
if duplicates:
|
if duplicates:
|
||||||
click.secho(
|
click.secho(
|
||||||
f"{len(duplicates)} transactions ignored (duplicates).", fg="yellow"
|
f"{len(duplicates)} transactions ignored (duplicates).", fg="yellow"
|
||||||
|
|
Loading…
Reference in a new issue