Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let CSV importer support tab-separated files #85

Open
l9i opened this issue Sep 12, 2020 · 4 comments
Open

Let CSV importer support tab-separated files #85

l9i opened this issue Sep 12, 2020 · 4 comments
Labels
CSV Related to the CSV importer

Comments

@l9i
Copy link

l9i commented Sep 12, 2020

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.

@jarofromel
Copy link

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')]

@dnicolodi
Copy link
Collaborator

This issue should be moved to beangulp.

@blais blais transferred this issue from beancount/beancount May 23, 2021
@l9i
Copy link
Author

l9i commented May 28, 2021

@jarifuri, I don't think this problem can be solved by passing csv_dialect since the MIME type matcher always expects text/csv:

matchers.append(('mime', 'text/csv'))

@dnicolodi
Copy link
Collaborator

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.

@dnicolodi dnicolodi added the CSV Related to the CSV importer label Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSV Related to the CSV importer
Projects
None yet
Development

No branches or pull requests

3 participants