beancount-gocardless 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- beancount_gocardless/client.py +24 -6
- beancount_gocardless/importer.py +11 -12
- {beancount_gocardless-0.1.6.dist-info → beancount_gocardless-0.1.7.dist-info}/METADATA +1 -1
- beancount_gocardless-0.1.7.dist-info/RECORD +9 -0
- beancount_gocardless-0.1.6.dist-info/RECORD +0 -9
- {beancount_gocardless-0.1.6.dist-info → beancount_gocardless-0.1.7.dist-info}/LICENSE +0 -0
- {beancount_gocardless-0.1.6.dist-info → beancount_gocardless-0.1.7.dist-info}/WHEEL +0 -0
- {beancount_gocardless-0.1.6.dist-info → beancount_gocardless-0.1.7.dist-info}/entry_points.txt +0 -0
beancount_gocardless/client.py
CHANGED
|
@@ -2,11 +2,27 @@ from datetime import timedelta, datetime
|
|
|
2
2
|
import requests_cache
|
|
3
3
|
import requests
|
|
4
4
|
from typing import TypedDict, Optional
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def cleanup_headers(response):
|
|
11
|
+
to_preserve = [
|
|
12
|
+
"Content-Type",
|
|
13
|
+
"Date",
|
|
14
|
+
"Content-Encoding",
|
|
15
|
+
"Content-Language",
|
|
16
|
+
"ETag",
|
|
17
|
+
"Last-Modified",
|
|
18
|
+
]
|
|
19
|
+
deleted = set()
|
|
20
|
+
to_preserve_lower = [h.lower() for h in to_preserve]
|
|
21
|
+
for header in response.headers.keys():
|
|
22
|
+
if header.lower() not in to_preserve_lower:
|
|
23
|
+
del response.headers[header]
|
|
24
|
+
deleted.add(header)
|
|
25
|
+
logger.info("Deleted headers: %s", ", ".join(deleted))
|
|
10
26
|
return response
|
|
11
27
|
|
|
12
28
|
|
|
@@ -63,7 +79,8 @@ class BaseService:
|
|
|
63
79
|
"expire_after": 0,
|
|
64
80
|
"old_data_on_error": True,
|
|
65
81
|
"match_headers": False,
|
|
66
|
-
"
|
|
82
|
+
"cache_control": False,
|
|
83
|
+
"response_hook": cleanup_headers,
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
def __init__(
|
|
@@ -146,6 +163,7 @@ class BaseService:
|
|
|
146
163
|
response = self.session.request(
|
|
147
164
|
method, url, headers=headers, params=params, data=data
|
|
148
165
|
)
|
|
166
|
+
logger.info("Response headers", response.headers)
|
|
149
167
|
|
|
150
168
|
# Retry once if token expired (401 Unauthorized)
|
|
151
169
|
if response.status_code == 401:
|
beancount_gocardless/importer.py
CHANGED
|
@@ -34,7 +34,7 @@ class NordigenImporter(beangulp.Importer):
|
|
|
34
34
|
self._client = NordigenClient(
|
|
35
35
|
self.config["secret_id"],
|
|
36
36
|
self.config["secret_key"],
|
|
37
|
-
cache_options=self.config.get(
|
|
37
|
+
cache_options=self.config.get("cache_options", None),
|
|
38
38
|
)
|
|
39
39
|
|
|
40
40
|
return self._client
|
|
@@ -116,7 +116,7 @@ class NordigenImporter(beangulp.Importer):
|
|
|
116
116
|
key=lambda x: x[0].get("valueDate") or x[0].get("bookingDate"),
|
|
117
117
|
)
|
|
118
118
|
|
|
119
|
-
def add_metadata(self, transaction,
|
|
119
|
+
def add_metadata(self, transaction, custom_metadata):
|
|
120
120
|
"""
|
|
121
121
|
Extracts metadata from a transaction and returns it as a dictionary.
|
|
122
122
|
|
|
@@ -124,7 +124,7 @@ class NordigenImporter(beangulp.Importer):
|
|
|
124
124
|
|
|
125
125
|
Args:
|
|
126
126
|
transaction (dict): The transaction data from the API.
|
|
127
|
-
|
|
127
|
+
custom_metadata (dict): Custom metadata from the config file.
|
|
128
128
|
|
|
129
129
|
Returns:
|
|
130
130
|
dict: A dictionary of metadata key-value pairs.
|
|
@@ -151,8 +151,7 @@ class NordigenImporter(beangulp.Importer):
|
|
|
151
151
|
if transaction.get("bookingDate"):
|
|
152
152
|
metakv["bookingDate"] = transaction["bookingDate"]
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
metakv["filing_account"] = filing_account
|
|
154
|
+
metakv.update(custom_metadata)
|
|
156
155
|
|
|
157
156
|
return metakv
|
|
158
157
|
|
|
@@ -223,11 +222,10 @@ class NordigenImporter(beangulp.Importer):
|
|
|
223
222
|
Returns:
|
|
224
223
|
str: The Beancount transaction flag.
|
|
225
224
|
"""
|
|
226
|
-
|
|
227
|
-
return flags.FLAG_OKAY
|
|
225
|
+
return flags.FLAG_OKAY if status == "booked" else flags.FLAG_WARNING
|
|
228
226
|
|
|
229
227
|
def create_transaction_entry(
|
|
230
|
-
self, transaction, status, asset_account,
|
|
228
|
+
self, transaction, status, asset_account, custom_metadata
|
|
231
229
|
):
|
|
232
230
|
"""
|
|
233
231
|
Creates a Beancount transaction entry from a Nordigen transaction.
|
|
@@ -238,12 +236,12 @@ class NordigenImporter(beangulp.Importer):
|
|
|
238
236
|
transaction (dict): The transaction data from the API.
|
|
239
237
|
status (str): The transaction status ('booked' or 'pending').
|
|
240
238
|
asset_account (str): The Beancount asset account.
|
|
241
|
-
|
|
239
|
+
custom_metadata (dict): Custom metadata from config
|
|
242
240
|
|
|
243
241
|
Returns:
|
|
244
242
|
data.Transaction: The created Beancount transaction entry.
|
|
245
243
|
"""
|
|
246
|
-
metakv = self.add_metadata(transaction,
|
|
244
|
+
metakv = self.add_metadata(transaction, custom_metadata)
|
|
247
245
|
meta = data.new_metadata("", 0, metakv)
|
|
248
246
|
|
|
249
247
|
trx_date = self.get_transaction_date(transaction)
|
|
@@ -294,14 +292,15 @@ class NordigenImporter(beangulp.Importer):
|
|
|
294
292
|
for account in self.config["accounts"]:
|
|
295
293
|
account_id = account["id"]
|
|
296
294
|
asset_account = account["asset_account"]
|
|
297
|
-
|
|
295
|
+
# Use get() with a default empty dict for custom_metadata
|
|
296
|
+
custom_metadata = account.get("metadata", {})
|
|
298
297
|
|
|
299
298
|
transactions_data = self.get_transactions_data(account_id)
|
|
300
299
|
all_transactions = self.get_all_transactions(transactions_data)
|
|
301
300
|
|
|
302
301
|
for transaction, status in all_transactions:
|
|
303
302
|
entry = self.create_transaction_entry(
|
|
304
|
-
transaction, status, asset_account,
|
|
303
|
+
transaction, status, asset_account, custom_metadata
|
|
305
304
|
)
|
|
306
305
|
entries.append(entry)
|
|
307
306
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
beancount_gocardless/__init__.py,sha256=Rf2-pfuaXaXPwBu3yEn2uXyOQ6uLyGxljJ5hoTCss5Y,100
|
|
2
|
+
beancount_gocardless/cli.py,sha256=ZdsdknScEOlUq_7rI0ixzN1UDh1dgUokzTzO_3WySqY,2407
|
|
3
|
+
beancount_gocardless/client.py,sha256=ubHY0oozTJD5Tb5hUH2u4aEgwymb3Y-bCmy-gtnMdVY,13019
|
|
4
|
+
beancount_gocardless/importer.py,sha256=tjNKPCYFddR62YDAXm6rfLqcVNeiGKWbVAEyoPWPekg,11151
|
|
5
|
+
beancount_gocardless-0.1.7.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
|
|
6
|
+
beancount_gocardless-0.1.7.dist-info/METADATA,sha256=FM32PtLlyhpogNVVGS3ypt5LpvjNUgPhcnIFZ6NadEw,2634
|
|
7
|
+
beancount_gocardless-0.1.7.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
8
|
+
beancount_gocardless-0.1.7.dist-info/entry_points.txt,sha256=fmhiRcNVrum0p30f5YNqvIYVEPXYsS5cP1xNkVmdn8k,70
|
|
9
|
+
beancount_gocardless-0.1.7.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
beancount_gocardless/__init__.py,sha256=Rf2-pfuaXaXPwBu3yEn2uXyOQ6uLyGxljJ5hoTCss5Y,100
|
|
2
|
-
beancount_gocardless/cli.py,sha256=ZdsdknScEOlUq_7rI0ixzN1UDh1dgUokzTzO_3WySqY,2407
|
|
3
|
-
beancount_gocardless/client.py,sha256=PHZQH3O122cqYsYZDdb1NEoYuS5NBJc0ZteostnMUbM,12511
|
|
4
|
-
beancount_gocardless/importer.py,sha256=TcwHnXFLBER6RGhd0siaK4kD6ToSdmvWODwh_ZfT6e4,11183
|
|
5
|
-
beancount_gocardless-0.1.6.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
|
|
6
|
-
beancount_gocardless-0.1.6.dist-info/METADATA,sha256=WZ5uXpof3dWLDVQFwM_7UX5i_I6y78tJ6A1oMHlE2s8,2634
|
|
7
|
-
beancount_gocardless-0.1.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
|
8
|
-
beancount_gocardless-0.1.6.dist-info/entry_points.txt,sha256=fmhiRcNVrum0p30f5YNqvIYVEPXYsS5cP1xNkVmdn8k,70
|
|
9
|
-
beancount_gocardless-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{beancount_gocardless-0.1.6.dist-info → beancount_gocardless-0.1.7.dist-info}/entry_points.txt
RENAMED
|
File without changes
|