tariochbctools 1.1.1__py2.py3-none-any.whl → 1.2.0__py2.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.
- tariochbctools/importers/radicant/__init__.py +0 -0
- tariochbctools/importers/radicant/importer.py +144 -0
- tariochbctools/plugins/__init__.py +1 -2
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info}/METADATA +3 -2
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info}/RECORD +9 -7
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info}/WHEEL +1 -1
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info}/entry_points.txt +0 -0
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info/licenses}/LICENSE.txt +0 -0
- {tariochbctools-1.1.1.dist-info → tariochbctools-1.2.0.dist-info}/top_level.txt +0 -0
File without changes
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import re
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
import beangulp
|
5
|
+
import camelot
|
6
|
+
from beancount.core import amount, data
|
7
|
+
from beancount.core.number import D
|
8
|
+
|
9
|
+
|
10
|
+
class Importer(beangulp.Importer):
|
11
|
+
"""An importer for radicant Account Statement PDF files."""
|
12
|
+
|
13
|
+
def __init__(self, filepattern: str, account: data.Account):
|
14
|
+
self._filepattern = filepattern
|
15
|
+
self._account = account
|
16
|
+
self.currency = "CHF"
|
17
|
+
|
18
|
+
def identify(self, filepath: str) -> bool:
|
19
|
+
return re.search(self._filepattern, filepath) is not None
|
20
|
+
|
21
|
+
def account(self, filepath: str) -> data.Account:
|
22
|
+
return self._account
|
23
|
+
|
24
|
+
def cleanAmount(
|
25
|
+
self, debit: str | None, credit: str | None
|
26
|
+
) -> amount.Amount | None:
|
27
|
+
if debit:
|
28
|
+
return -amount.Amount(D(debit.replace("'", "")), self.currency)
|
29
|
+
elif credit:
|
30
|
+
return amount.Amount(D(credit.replace("'", "")), self.currency)
|
31
|
+
else:
|
32
|
+
return None
|
33
|
+
|
34
|
+
def createEntry(
|
35
|
+
self,
|
36
|
+
filepath: str,
|
37
|
+
date: str,
|
38
|
+
amt: amount.Amount,
|
39
|
+
text: str,
|
40
|
+
conversionOriginal: str | None,
|
41
|
+
conversionRate: str | None,
|
42
|
+
) -> data.Transaction:
|
43
|
+
|
44
|
+
book_date = datetime.strptime(date, "%d.%m.%y").date()
|
45
|
+
|
46
|
+
if conversionOriginal and conversionRate:
|
47
|
+
kv = {"original": conversionOriginal, "rate": conversionRate}
|
48
|
+
text = text.replace("Amount: " + conversionOriginal, "")
|
49
|
+
else:
|
50
|
+
kv = None
|
51
|
+
|
52
|
+
meta = data.new_metadata(filepath, 0, kv)
|
53
|
+
return data.Transaction(
|
54
|
+
meta,
|
55
|
+
book_date,
|
56
|
+
"*",
|
57
|
+
"",
|
58
|
+
text.strip(),
|
59
|
+
data.EMPTY_SET,
|
60
|
+
data.EMPTY_SET,
|
61
|
+
[
|
62
|
+
data.Posting(self._account, amt, None, None, None, None),
|
63
|
+
],
|
64
|
+
)
|
65
|
+
|
66
|
+
def extract(self, filepath: str, existing: data.Entries) -> data.Entries:
|
67
|
+
entries = []
|
68
|
+
|
69
|
+
conversionPattern = re.compile(r"(?P<original>.+) at the rate of (?P<rate>.+)")
|
70
|
+
|
71
|
+
tables = camelot.read_pdf(
|
72
|
+
filepath,
|
73
|
+
flavor="stream",
|
74
|
+
pages="all",
|
75
|
+
table_regions=["40,470,580,32"],
|
76
|
+
columns=["80,300,370,440,500"],
|
77
|
+
)
|
78
|
+
|
79
|
+
for table in tables:
|
80
|
+
df = table.df
|
81
|
+
|
82
|
+
lastTrxDate = None
|
83
|
+
lastAmount = None
|
84
|
+
lastDetails = ""
|
85
|
+
beforeStart = True
|
86
|
+
conversionOriginal = None
|
87
|
+
conversionRate = None
|
88
|
+
for _, row in df.iterrows():
|
89
|
+
date, text, _, debit, credit, _ = tuple(row)
|
90
|
+
|
91
|
+
# skip stuff before
|
92
|
+
if beforeStart and "Date" != date:
|
93
|
+
continue
|
94
|
+
elif "Date" == date:
|
95
|
+
beforeStart = False
|
96
|
+
continue
|
97
|
+
|
98
|
+
# skip stuff after
|
99
|
+
if "Balance as of" in text:
|
100
|
+
break
|
101
|
+
|
102
|
+
trxDate = date
|
103
|
+
details = text.strip()
|
104
|
+
amt = self.cleanAmount(debit, credit)
|
105
|
+
|
106
|
+
if amt:
|
107
|
+
if lastTrxDate:
|
108
|
+
entries.append(
|
109
|
+
self.createEntry(
|
110
|
+
filepath,
|
111
|
+
lastTrxDate,
|
112
|
+
lastAmount,
|
113
|
+
lastDetails,
|
114
|
+
conversionOriginal,
|
115
|
+
conversionRate,
|
116
|
+
)
|
117
|
+
)
|
118
|
+
|
119
|
+
lastTrxDate = trxDate
|
120
|
+
lastAmount = amt
|
121
|
+
lastDetails = ""
|
122
|
+
conversionOriginal = None
|
123
|
+
conversionRate = None
|
124
|
+
|
125
|
+
match = conversionPattern.match(details)
|
126
|
+
if match:
|
127
|
+
conversionOriginal = match.group("original")
|
128
|
+
conversionRate = match.group("rate")
|
129
|
+
else:
|
130
|
+
lastDetails += details + " "
|
131
|
+
|
132
|
+
if lastTrxDate:
|
133
|
+
entries.append(
|
134
|
+
self.createEntry(
|
135
|
+
filepath,
|
136
|
+
lastTrxDate,
|
137
|
+
lastAmount,
|
138
|
+
lastDetails,
|
139
|
+
conversionOriginal,
|
140
|
+
conversionRate,
|
141
|
+
)
|
142
|
+
)
|
143
|
+
|
144
|
+
return entries
|
@@ -1,2 +1 @@
|
|
1
|
-
"""Beancount plugins.
|
2
|
-
"""
|
1
|
+
"""Beancount plugins."""
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: tariochbctools
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.2.0
|
4
4
|
Summary: Importers, plugins and price fetchers for Beancount
|
5
5
|
Home-page: https://github.com/tarioch/beancounttools/
|
6
6
|
Author: Patrick Ruckstuhl
|
@@ -41,6 +41,7 @@ Requires-Dist: pytest-mock; extra == "testing"
|
|
41
41
|
Requires-Dist: flake8; extra == "testing"
|
42
42
|
Requires-Dist: black; extra == "testing"
|
43
43
|
Requires-Dist: isort; extra == "testing"
|
44
|
+
Dynamic: license-file
|
44
45
|
|
45
46
|
.. image:: https://img.shields.io/pypi/l/tariochbctools.svg
|
46
47
|
:target: https://pypi.python.org/pypi/tariochbctools
|
@@ -26,6 +26,8 @@ tariochbctools/importers/postfinance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeu
|
|
26
26
|
tariochbctools/importers/postfinance/importer.py,sha256=PLBbnswb_tHt8wzd7yCC4UAWHoPn3WcJIXaOMewz6fc,2524
|
27
27
|
tariochbctools/importers/quickfile/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
28
28
|
tariochbctools/importers/quickfile/importer.py,sha256=HgS7lSi7egxkj-IWd77MS-vhepYNCRXZwVbeCornkzg,6479
|
29
|
+
tariochbctools/importers/radicant/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
30
|
+
tariochbctools/importers/radicant/importer.py,sha256=39FyeVGvhG4tcRXVJWxbQpEGneMj7WUfRTqP0FvXtsA,4382
|
29
31
|
tariochbctools/importers/raiffeisench/importer.py,sha256=5r7hHEG0ZtEp-ePlsF4aHapBv9DJgjeVxE1m_G62bLU,912
|
30
32
|
tariochbctools/importers/revolut/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
31
33
|
tariochbctools/importers/revolut/importer.py,sha256=5jI91gGIDcP2TMFcauKkA9OWCTqCIl5Phz9n6r9kOeI,3953
|
@@ -43,14 +45,14 @@ tariochbctools/importers/zak/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
|
|
43
45
|
tariochbctools/importers/zak/importer.py,sha256=_2z-O1IHK-HZOrbAatUiCY2rkLIhYvBeT6DXk4B0KNw,4104
|
44
46
|
tariochbctools/importers/zkb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
45
47
|
tariochbctools/importers/zkb/importer.py,sha256=Gm3ql1OHp0dFzJHph1dqyfF4zHNAo00VEiO-WXowtwY,1490
|
46
|
-
tariochbctools/plugins/__init__.py,sha256=
|
48
|
+
tariochbctools/plugins/__init__.py,sha256=zm0w6RQz3txAdw7iNI6D_0QvpO-SURNzBdG98ZCk9Os,25
|
47
49
|
tariochbctools/plugins/check_portfolio_sum.py,sha256=naJ2j6BFpQhJhT2c-gfjyIdcYe0l_ZzpdlqgwrsIv2g,2340
|
48
50
|
tariochbctools/plugins/generate_base_ccy_prices.py,sha256=4CDzUosjMWCZfsBJMLrf-i5WNCHexI2rdm5vIDYW-AI,1314
|
49
51
|
tariochbctools/plugins/prices/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
50
52
|
tariochbctools/plugins/prices/ibkr.py,sha256=GYCjnlF-MK-ZFPEr0M6T4iO3Etq0tMmrMlsHGInXUO8,1405
|
51
|
-
tariochbctools-1.
|
52
|
-
tariochbctools-1.
|
53
|
-
tariochbctools-1.
|
54
|
-
tariochbctools-1.
|
55
|
-
tariochbctools-1.
|
56
|
-
tariochbctools-1.
|
53
|
+
tariochbctools-1.2.0.dist-info/licenses/LICENSE.txt,sha256=VR2hkz3p9Sw4hSXc7S5iZTOXGeV4h-i8AO_q0zEmtkE,1074
|
54
|
+
tariochbctools-1.2.0.dist-info/METADATA,sha256=d6JjInnjmy8_4_Hac5SQ8R11U81LHLndOWIvFAQ8YBw,2190
|
55
|
+
tariochbctools-1.2.0.dist-info/WHEEL,sha256=_itY3bZllKbLk93i0gzNzdweAt5eocJdfN7atrjOnvQ,109
|
56
|
+
tariochbctools-1.2.0.dist-info/entry_points.txt,sha256=9xrCCY1wx2zCIsQUOWZelLHDmHw9Oc-ZBAKUIY9lKTA,88
|
57
|
+
tariochbctools-1.2.0.dist-info/top_level.txt,sha256=CiA_NepCI6zDNsaORA55zmpuJFSnTvLESraIL13xiOQ,15
|
58
|
+
tariochbctools-1.2.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|