Add importer for Statiegeld Nederland
This commit is contained in:
parent
3351e2d0d4
commit
d48a4dfd87
10 changed files with 67 additions and 0 deletions
|
@ -41,6 +41,7 @@ if __name__ == "__main__":
|
|||
importers = [
|
||||
rabobank.Importer("Activa:Betaalrekening", "EUR"),
|
||||
pdf.MollieInvoiceImporter(),
|
||||
pdf.StatiegeldImporter(),
|
||||
]
|
||||
hooks = [classify_contra(rabobank.guess_contra, "Activa:Betaalrekening")]
|
||||
main = Ingest(importers, hooks)
|
||||
|
|
|
@ -84,3 +84,48 @@ class MollieInvoiceImporter(Importer):
|
|||
],
|
||||
)
|
||||
return [tx, doc]
|
||||
|
||||
|
||||
class StatiegeldImporter(Importer):
|
||||
def identify(self, filepath):
|
||||
mimetype, encoding = mimetypes.guess_type(filepath)
|
||||
if mimetype != "application/pdf":
|
||||
return False
|
||||
|
||||
lines = pdf_to_text(filepath).split("\n")
|
||||
return any(line.startswith("Statiegeld Nederland") for line in lines)
|
||||
|
||||
def account(self, filepath):
|
||||
return "Inkomsten:Statiegeld"
|
||||
|
||||
def tx_ref(self, filepath):
|
||||
lines = pdf_to_text(filepath).split("\n")
|
||||
for line in lines:
|
||||
if m := re.search(r"^Factuurnr : (RP\d+)$", line):
|
||||
return f"SNL-{m[1]}"
|
||||
raise Exception("Mollie invoice reference not found")
|
||||
|
||||
def filename(self, filepath):
|
||||
return f"{self.tx_ref(filepath)}.pdf"
|
||||
|
||||
def date(self, filepath):
|
||||
lines = pdf_to_text(filepath).split("\n")
|
||||
for line in lines:
|
||||
if m := re.search(r"^Datum : (\d{2})/(\d{2})/(\d{4})$", line):
|
||||
return date(int(m[3]), int(m[2]), int(m[1]))
|
||||
raise Exception("Date not found")
|
||||
|
||||
def extract(self, filepath, existing):
|
||||
name = self.filename(filepath)
|
||||
date = self.date(filepath)
|
||||
link = self.tx_ref(filepath)
|
||||
|
||||
doc = Document(
|
||||
meta=data.new_metadata(filepath, 0),
|
||||
date=date,
|
||||
account=self.account(filepath),
|
||||
filename=f"docs/Inkomsten/Statiegeld/{date}.{name}",
|
||||
tags=set(),
|
||||
links={link},
|
||||
)
|
||||
return [doc]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue