Files
Beancount-importer/importers/csvbank.py

36 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-08-17 17:20:23 +00:00
import os
from beangulp import mimetypes
from beangulp.importers import csvbase
from beangulp.testing import main as testing_main
class Importer(csvbase.Importer):
# TODO Deutscher CSV header überprüfen: Posting Date ; Description ; Note ; Amount, Balance
date = csvbase.Date('Posting Date', '%Y-%m-%d') # ! date-Format anpassen
narration = csvbase.Columns('Description', 'Note', sep='; ')
amount = csvbase.Amount('Amount')
balance = csvbase.Amount('Balance')
""" Date,Posting Date,Description,Note,Amount,Balance
2025-08-01,2025-08-01,Grocery Store,, -54.20,1245.80
2025-08-03,2025-08-03,Salary,, 2500.00,3745.80
"""
def identify(self, filepath):
mimetype, _ = mimetypes.guess_type(filepath)
if mimetype != 'text/csv':
return false
with open(filepath, encoding='utf-8') as f:
header = f.readline()
# ! TODO
return header.startswith('Date, Posting Date, Description, Amount')
def filename(self, filepath):
name = os.path.basename(filepath)
return f'csvbank.{name}'
# ? Testing
__name__ '__main__':
# Test-Runner und CLI
testing_main(Importer('Assets:Bank:Checking', 'EUR'))