tariochbctools 1.1.0__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.
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."""
@@ -13,7 +13,11 @@ def generate(entries, options_map, baseCcy):
13
13
 
14
14
  additionalEntries = []
15
15
  for entry in entries:
16
- if isinstance(entry, data.Price) and entry.amount.currency != baseCcy:
16
+ if (
17
+ isinstance(entry, data.Price)
18
+ and entry.amount.currency != baseCcy
19
+ and entry.currency != baseCcy
20
+ ):
17
21
  fxTuple = tuple([entry.amount.currency, baseCcy])
18
22
  fxRate = prices.get_price(priceMap, fxTuple, entry.date)
19
23
  if fxRate[1] and not _alreadyExistingPrice(
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: tariochbctools
3
- Version: 1.1.0
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=DSZtoTVosmExbFmMlHVrZAxKewEILDZlGh_7-uWcc_w,26
48
+ tariochbctools/plugins/__init__.py,sha256=zm0w6RQz3txAdw7iNI6D_0QvpO-SURNzBdG98ZCk9Os,25
47
49
  tariochbctools/plugins/check_portfolio_sum.py,sha256=naJ2j6BFpQhJhT2c-gfjyIdcYe0l_ZzpdlqgwrsIv2g,2340
48
- tariochbctools/plugins/generate_base_ccy_prices.py,sha256=Phw314qox3jpNgC5-GcnmyYcLkMkrd8xsWS-wYwdj6o,1236
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.1.0.dist-info/LICENSE.txt,sha256=VR2hkz3p9Sw4hSXc7S5iZTOXGeV4h-i8AO_q0zEmtkE,1074
52
- tariochbctools-1.1.0.dist-info/METADATA,sha256=1Xewhm6I-36FpKtMwBGx1lUa9_QK7joDjJxBbvrk5PY,2168
53
- tariochbctools-1.1.0.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
54
- tariochbctools-1.1.0.dist-info/entry_points.txt,sha256=9xrCCY1wx2zCIsQUOWZelLHDmHw9Oc-ZBAKUIY9lKTA,88
55
- tariochbctools-1.1.0.dist-info/top_level.txt,sha256=CiA_NepCI6zDNsaORA55zmpuJFSnTvLESraIL13xiOQ,15
56
- tariochbctools-1.1.0.dist-info/RECORD,,
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (80.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py2-none-any
5
5
  Tag: py3-none-any