beangulp
beangulp copied to clipboard
Let CSV importer support tab-separated files
Would it be possible for the CSV importer to support tab-separated files as well? Currently the 'text/csv' MIME type seems hardcoded.
While I could monkey patch it with self.remap['mime'] = [re.compile('text/tab-separated-values')]
in my subclass' __init__()
, it'd be rather ugly.
There is an argument to CSV importer - csv_dialect. It allows you to define your own way to parse your csv file (on the positive side, it is the part of the Python standard library), see https://docs.python.org/3/library/csv.html#csv-fmt-params .
Simple example of the configuration file
from beancount.ingest.importers import csv
from csv import register_dialect
register_dialect('own', 'excel', delimiter='\t')
CONFIG = [csv.Importer({csv.Col.DATE: 'Booking Date',
csv.Col.PAYEE: 'Beneficiary',
csv.Col.AMOUNT:'Amount'},
'Assets:CZ:Unicredit:Current', 'CZK',
csv_dialect='own')]
This issue should be moved to beangulp.
@jarifuri, I don't think this problem can be solved by passing csv_dialect
since the MIME type matcher always expects text/csv
: https://github.com/beancount/beangulp/blob/44d235b80cec8d98ed2ba4dfc368b741f3c77abd/beangulp/importers/csv.py#L181
I don't see anything wrong with overriding the mime type matching in a subclass. Anyhow, the this CSV importer is deprecated and replaced by beangulp.importers.csvbase.Importer
.