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

Pre-processing of CSV #66

Closed
elChapoSing opened this issue May 6, 2020 · 2 comments
Closed

Pre-processing of CSV #66

elChapoSing opened this issue May 6, 2020 · 2 comments

Comments

@elChapoSing
Copy link

elChapoSing commented May 6, 2020

Hello,

Great job on the library it's incredibly useful.

Would it make sense to add a pre-processing sequence the same way you have different mappings ?

My bank has incredibly badly formed CSV so I need to pre-process it to have it match the format that csv2ofx can understand. I am assuming this is something that a lot of people have encountered.

The code would look something like :

from __future__ import absolute_import, print_function

import itertools as it

from meza.io import read_csv, IterStringIO
from csv2ofx import utils
from csv2ofx.ofx import OFX
from csv2ofx.mappings.default import mapping

#new import
from csv2ofx.processing.default import pre_process
#new import

ofx = OFX(mapping)

#to be used here
records = read_csv(pre_process('path/to/file.csv'))
#to be used here

groups = ofx.gen_groups(records)
trxns = ofx.gen_trxns(groups)
cleaned_trxns = ofx.clean_trxns(trxns)
data = utils.gen_data(cleaned_trxns)
content = it.chain([ofx.header(), ofx.gen_body(data), ofx.footer()])

for line in IterStringIO(content):
    print(line)

where pre_process would be a function taking a path and returning a StringIO.
You could then have pre-processing for a bunch of counterparties that do not know how to output proper CSV.
Does any of this make sense ?

@reubano
Copy link
Owner

reubano commented Dec 25, 2021

CR #83

@reubano
Copy link
Owner

reubano commented Jun 8, 2022

I'd rather not complicate this script by doing additional pre-processing. There are various commands you can run your file through before piping to csv2ofx. E.g. to strip the last 2 lines of a csv file, head -n -2 transactions.csv | csv2ofx -x /path/to/mapping.py

@reubano reubano closed this as completed Jun 8, 2022
reubano added a commit that referenced this issue Jun 9, 2022
Skipping trailing rows/cols to come soon
reubano added a commit that referenced this issue Jun 9, 2022
* features:
  Bump to version 0.30.0
  [NEW] Add option to set last row (fixes #83)
  [NEW] Add transaction filters (fixes #83)
  [NEW] Skip initial rows/columns (fixes #66, #67, and #83)
  [DOC] Update/correct mapping documentation (closes #16)
  [DOC] Update readme content
  Fix chunksize default value spacing and update readme
  [FIX] Make has_header optional (defaults to True)
  Test foreign currency (closes #70)
  [NEW] Add date parsing format option (closes #60)
  [DOC] Clarify how date_fmt is used (close #60)
  [ENH] Add `dayfirst` option/kwarg (closes #39)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants