Skip to content

Commit 3984ebd

Browse files
committed
black: reformat project to line-length=125
1 parent 2cad2ec commit 3984ebd

File tree

8 files changed

+70
-62
lines changed

8 files changed

+70
-62
lines changed

ynab_sync/cli.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .quickstart import quickstart # noqa
2525

2626
logging.basicConfig(
27-
level=logging.INFO,
27+
level=logging.DEBUG,
2828
format="%(asctime)s %(name)s [%(levelname)s] %(message)s",
2929
handlers=[logging.StreamHandler(sys.stdout)],
3030
)
@@ -96,9 +96,7 @@ def upload(
9696
ynab_account_id=UUID(ynab_account_id),
9797
)
9898

99-
upload_to_ynab(
100-
transactions=ynab_transactions, token=ynab_token, budget_id=UUID(ynab_budget_id)
101-
)
99+
upload_to_ynab(transactions=ynab_transactions, token=ynab_token, budget_id=UUID(ynab_budget_id))
102100

103101

104102
@app.command()
@@ -188,9 +186,7 @@ def generate_bank_auth_link(
188186
"Open this link in your browser and proceed with authorization:",
189187
requisition.link,
190188
)
191-
print(
192-
"Run `gocardless list_requisition_accounts` afterwards to get GOCARDLESS_ACCOUNT_ID"
193-
)
189+
print("Run `gocardless list_requisition_accounts` afterwards to get GOCARDLESS_ACCOUNT_ID")
194190

195191

196192
@app.command("gocardless").command()

ynab_sync/gocardless/api.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
import requests
55

6-
from .models import (GoCardlessBankAccountData, GoCardlessInstitution,
7-
GoCardlessRequisition)
6+
from .models import GoCardlessBankAccountData, GoCardlessInstitution, GoCardlessRequisition
87

98
BASE_URL = "https://bankaccountdata.gocardless.com/api/v2"
109

@@ -32,9 +31,7 @@ def _get_token(
3231
def _requests_session(self) -> requests.Session:
3332
if self._request_session is None:
3433
self._request_session = requests.Session()
35-
self._request_session.headers.update(
36-
{"Authorization": f"Bearer {self._get_token()}"}
37-
)
34+
self._request_session.headers.update({"Authorization": f"Bearer {self._get_token()}"})
3835

3936
return self._request_session
4037

@@ -70,9 +67,7 @@ def get_transactions(
7067
return GoCardlessBankAccountData(**json_data)
7168

7269
def get_banks(self, country: str) -> list[GoCardlessInstitution]:
73-
response = self._requests_session.get(
74-
f"{BASE_URL}/institutions/?country={country}"
75-
)
70+
response = self._requests_session.get(f"{BASE_URL}/institutions/?country={country}")
7671
response.raise_for_status()
7772
json_data = response.json()
7873
return [GoCardlessInstitution(**institution) for institution in json_data]
@@ -84,9 +79,7 @@ def get_requisition(self, requisition_id: str) -> GoCardlessRequisition:
8479
response.raise_for_status()
8580
return GoCardlessRequisition(**response.json())
8681

87-
def post_requisition(
88-
self, redirect: str, institution_id: str
89-
) -> GoCardlessRequisition:
82+
def post_requisition(self, redirect: str, institution_id: str) -> GoCardlessRequisition:
9083
response = self._requests_session.post(
9184
f"{BASE_URL}/requisitions/",
9285
json={"redirect": redirect, "institution_id": institution_id},

ynab_sync/gocardless/data.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
op_test_data = {'transactions': {'booked': [{'transactionId': '202308015931560N0164', 'bookingDate': '2023-08-01', 'valueDate': '2023-08-01', 'transactionAmount': {'amount': '400.00', 'currency': 'EUR'}, 'debtorName': 'ATAVIN ALEKSEI', 'remittanceInformationUnstructured': 'Withdrawal from savings target Vero\nhailinto', 'proprietaryBankTransactionCode': 'PANO', 'internalTransactionId': '8487f5c2f06e427b977beac249620ad7'}, {'transactionId': '202308015EQEO1540754', 'bookingDate': '2023-08-01', 'valueDate': '2023-08-01', 'transactionAmount': {'amount': '-25.47', 'currency': 'EUR'}, 'creditorName': 'LIDL HELSINKI-ROIHU HELSINKI', 'remittanceInformationUnstructured': '492065******9084 OSTOPVM 230731\nMF NRO 74570003213821301044336 \nVARMENTAJA 400', 'proprietaryBankTransactionCode': 'PKORTTIMAKSU', 'internalTransactionId': '738bddf4cebd9667e4a2ce16a5c4a2bc'}, {'transactionId': '202308015EQEL1086628', 'bookingDate': '2023-08-01', 'valueDate': '2023-08-01', 'transactionAmount': {'amount': '-2.99', 'currency': 'EUR'}, 'creditorName': 'APPLE.COM/BILL CORK', 'remittanceInformationUnstructured': '492065******9084 OSTOPVM 230731\nMF NRO 74601003212330187293060 \nVARMENTAJA 400', 'proprietaryBankTransactionCode': 'PKORTTIMAKSU', 'internalTransactionId': '26b9473190d0933146e74df10759fe91'}, {'transactionId': '202303245936191K8543', 'entryReference': 'RF14200185090845', 'bookingDate': '2023-08-01', 'valueDate': '2023-08-01', 'transactionAmount': {'amount': '-397.20', 'currency': 'EUR'}, 'creditorName': 'Verohailinto', 'creditorAccount': {'iban': 'FI5689199710000724'}, 'proprietaryBankTransactionCode': 'TILISIIRTO', 'internalTransactionId': 'b9661357cc5ee85edec599eaa037cb2c'}], 'pending': []}}
1+
op_test_data = {
2+
"transactions": {
3+
"booked": [
4+
{
5+
"transactionId": "202308015931560N0164",
6+
"bookingDate": "2023-08-01",
7+
"valueDate": "2023-08-01",
8+
"transactionAmount": {"amount": "400.00", "currency": "EUR"},
9+
"debtorName": "ATAVIN ALEKSEI",
10+
"remittanceInformationUnstructured": "Withdrawal from savings target Vero\nhailinto",
11+
"proprietaryBankTransactionCode": "PANO",
12+
"internalTransactionId": "8487f5c2f06e427b977beac249620ad7",
13+
},
14+
{
15+
"transactionId": "202308015EQEO1540754",
16+
"bookingDate": "2023-08-01",
17+
"valueDate": "2023-08-01",
18+
"transactionAmount": {"amount": "-25.47", "currency": "EUR"},
19+
"creditorName": "LIDL HELSINKI-ROIHU HELSINKI",
20+
"remittanceInformationUnstructured": "492065******9084 OSTOPVM 230731\nMF NRO 74570003213821301044336 \nVARMENTAJA 400",
21+
"proprietaryBankTransactionCode": "PKORTTIMAKSU",
22+
"internalTransactionId": "738bddf4cebd9667e4a2ce16a5c4a2bc",
23+
},
24+
{
25+
"transactionId": "202308015EQEL1086628",
26+
"bookingDate": "2023-08-01",
27+
"valueDate": "2023-08-01",
28+
"transactionAmount": {"amount": "-2.99", "currency": "EUR"},
29+
"creditorName": "APPLE.COM/BILL CORK",
30+
"remittanceInformationUnstructured": "492065******9084 OSTOPVM 230731\nMF NRO 74601003212330187293060 \nVARMENTAJA 400",
31+
"proprietaryBankTransactionCode": "PKORTTIMAKSU",
32+
"internalTransactionId": "26b9473190d0933146e74df10759fe91",
33+
},
34+
{
35+
"transactionId": "202303245936191K8543",
36+
"entryReference": "RF14200185090845",
37+
"bookingDate": "2023-08-01",
38+
"valueDate": "2023-08-01",
39+
"transactionAmount": {"amount": "-397.20", "currency": "EUR"},
40+
"creditorName": "Verohailinto",
41+
"creditorAccount": {"iban": "FI5689199710000724"},
42+
"proprietaryBankTransactionCode": "TILISIIRTO",
43+
"internalTransactionId": "b9661357cc5ee85edec599eaa037cb2c",
44+
},
45+
],
46+
"pending": [],
47+
}
48+
}

ynab_sync/gocardless/models.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ class GoCardlessTransaction(BaseModel):
1717
debtor_name: str | None = Field(alias="debtorName", default=None)
1818
creditor_name: str | None = Field(alias="creditorName", default=None)
1919
debtor_account: dict | None = Field(alias="debtorAccount", default=None)
20-
remittance_information_unstructured: str = Field(
21-
alias="remittanceInformationUnstructured", default=""
22-
)
23-
proprietary_bank_transaction_code: str | None = Field(
24-
alias="proprietaryBankTransactionCode", default=None
25-
)
20+
remittance_information_unstructured: str = Field(alias="remittanceInformationUnstructured", default="")
21+
proprietary_bank_transaction_code: str | None = Field(alias="proprietaryBankTransactionCode", default=None)
2622
bank_transaction_code: str | None = Field(alias="bankTransactionCode", default=None)
2723

2824

ynab_sync/logic.py

+7-21
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@ def get_gocardless_transactions(
2828
try:
2929
gocardless_api = GoCardLessAPI(secret_id=secret_id, secret_key=secret_key)
3030

31-
return gocardless_api.get_transactions(
32-
account_id=account_id, date_from=date_from, date_to=date_to
33-
)
31+
return gocardless_api.get_transactions(account_id=account_id, date_from=date_from, date_to=date_to)
3432
except HTTPError as exc:
3533
log.exception("GoCardless returned HTTPError", exc_info=exc)
3634
raise
3735

3836

39-
def prepare_ynab_transactions(
40-
gocardless_bank_data: GoCardlessBankAccountData, ynab_account_id: UUID
41-
) -> YNABTransactions:
37+
def prepare_ynab_transactions(gocardless_bank_data: GoCardlessBankAccountData, ynab_account_id: UUID) -> YNABTransactions:
4238
log = logging.getLogger("logic.prepare_ynab_transactions")
4339
transactions = []
4440
occurances = defaultdict(int)
@@ -57,9 +53,7 @@ def prepare_ynab_transactions(
5753
account_id=ynab_account_id,
5854
date=gocardless_transaction.booking_date,
5955
amount=amount,
60-
payee_name=gocardless_transaction.creditor_name
61-
or gocardless_transaction.debtor_name
62-
or "",
56+
payee_name=gocardless_transaction.creditor_name or gocardless_transaction.debtor_name or "",
6357
memo=memo,
6458
cleared="cleared",
6559
approved=False,
@@ -88,9 +82,7 @@ def upload_to_ynab(
8882
transactions_json = transactions.model_dump_json()
8983

9084
try:
91-
response = ynab_api.post_transactions(
92-
budget_id=budget_id, json_data=transactions_json
93-
)
85+
response = ynab_api.post_transactions(budget_id=budget_id, json_data=transactions_json)
9486
except HTTPError as exc:
9587
log.exception(
9688
"YNAB returned HTTPError: payload: %s",
@@ -112,9 +104,7 @@ def get_ynab_budget(token: str, budget_id: UUID) -> YNABBudget:
112104
return ynab_api.get_budget(budget_id=budget_id)
113105

114106

115-
def get_gocardless_banks(
116-
secret_id: str, secret_key: str, country: str
117-
) -> list[GoCardlessInstitution]:
107+
def get_gocardless_banks(secret_id: str, secret_key: str, country: str) -> list[GoCardlessInstitution]:
118108
gocardless_api = GoCardLessAPI(secret_id=secret_id, secret_key=secret_key)
119109
return gocardless_api.get_banks(country=country)
120110

@@ -126,13 +116,9 @@ def create_gocardless_requisition(
126116
redirect: str,
127117
) -> GoCardlessRequisition:
128118
gocardless_api = GoCardLessAPI(secret_id=secret_id, secret_key=secret_key)
129-
return gocardless_api.post_requisition(
130-
redirect=redirect, institution_id=institution_id
131-
)
119+
return gocardless_api.post_requisition(redirect=redirect, institution_id=institution_id)
132120

133121

134-
def get_gocardless_requisition(
135-
secret_id: str, secret_key: str, requisition_id: str
136-
) -> GoCardlessRequisition:
122+
def get_gocardless_requisition(secret_id: str, secret_key: str, requisition_id: str) -> GoCardlessRequisition:
137123
gocardless_api = GoCardLessAPI(secret_id=secret_id, secret_key=secret_key)
138124
return gocardless_api.get_requisition(requisition_id=requisition_id)

ynab_sync/tests/test_e2e.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from ..cli import upload
99
from ..gocardless.api import BASE_URL as GOCARDLESS_BASE_URL
1010
from ..tests.data.gocardless import TEST_GOCARDLESS_TRANSACTIONS
11-
from ..tests.data.ynab import (TEST_YNAB_REQUEST_TRANSACTIONS,
12-
TEST_YNAB_RESPONSE_TRANSACTIONS)
11+
from ..tests.data.ynab import TEST_YNAB_REQUEST_TRANSACTIONS, TEST_YNAB_RESPONSE_TRANSACTIONS
1312
from ..ynab.api import BASE_URL as YNAB_BASE_URL
1413

1514
TEST_YNAB_TOKEN = "TEST_YNAB_TOKEN"
@@ -52,9 +51,7 @@ def fixture_gocardless_get_transactions() -> None:
5251
json=json.loads(TEST_GOCARDLESS_TRANSACTIONS),
5352
status=HTTPStatus.OK,
5453
match=[
55-
responses.matchers.header_matcher(
56-
{"Authorization": f"Bearer {TEST_GOCARDLESS_ACCESS_TOKEN}"}
57-
),
54+
responses.matchers.header_matcher({"Authorization": f"Bearer {TEST_GOCARDLESS_ACCESS_TOKEN}"}),
5855
# TODO: add date_from/date_to matcher
5956
],
6057
)
@@ -68,12 +65,8 @@ def fixture_ynab_post_transactions() -> None:
6865
json=json.loads(TEST_YNAB_RESPONSE_TRANSACTIONS),
6966
status=HTTPStatus.OK,
7067
match=[
71-
responses.matchers.header_matcher(
72-
{"Authorization": f"Bearer {TEST_YNAB_TOKEN}"}
73-
),
74-
responses.matchers.json_params_matcher(
75-
json.loads(TEST_YNAB_REQUEST_TRANSACTIONS)
76-
),
68+
responses.matchers.header_matcher({"Authorization": f"Bearer {TEST_YNAB_TOKEN}"}),
69+
responses.matchers.json_params_matcher(json.loads(TEST_YNAB_REQUEST_TRANSACTIONS)),
7770
],
7871
)
7972

ynab_sync/tests/test_gocardless.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
from ..gocardless.api import GoCardLessAPI
88
from ..gocardless.models import GoCardlessBankAccountData
9-
from .data.gocardless import \
10-
TEST_GOCARDLESS_TRANSACTIONS as GOCARDLESS_TRANSACTIONS
9+
from .data.gocardless import TEST_GOCARDLESS_TRANSACTIONS as GOCARDLESS_TRANSACTIONS
1110

1211
SECRET_ID = os.getenv("GOCARDLESS_SECRET_ID", "")
1312
SECRET_KEY = os.getenv("GOCARDLESS_SECRET_KEY", "")

ynab_sync/ynab/api.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ def __init__(self, access_token: str):
1616
def _requests_session(self) -> requests.Session:
1717
if self._request_session is None:
1818
self._request_session = requests.Session()
19-
self._request_session.headers.update(
20-
{"Authorization": f"Bearer {self._access_token}"}
21-
)
19+
self._request_session.headers.update({"Authorization": f"Bearer {self._access_token}"})
2220

2321
return self._request_session
2422

0 commit comments

Comments
 (0)