csv2ofx 0.32.0__tar.gz → 0.33.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/MANIFEST.in +1 -1
- {csv2ofx-0.32.0/csv2ofx.egg-info → csv2ofx-0.33.0}/PKG-INFO +49 -52
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/README.md +42 -51
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/__init__.py +14 -22
- csv2ofx-0.33.0/csv2ofx/__main__.py +3 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/main.py +21 -20
- csv2ofx-0.33.0/csv2ofx/mappings/__init__.py +6 -0
- csv2ofx-0.33.0/csv2ofx/mappings/abnamro.py +12 -0
- csv2ofx-0.33.0/csv2ofx/mappings/amazon.py +60 -0
- csv2ofx-0.33.0/csv2ofx/mappings/boursorama.py +17 -0
- csv2ofx-0.33.0/csv2ofx/mappings/capitalone.py +15 -0
- csv2ofx-0.33.0/csv2ofx/mappings/creditunion.py +14 -0
- csv2ofx-0.33.0/csv2ofx/mappings/custom.py +21 -0
- csv2ofx-0.33.0/csv2ofx/mappings/default.py +17 -0
- csv2ofx-0.33.0/csv2ofx/mappings/eqbank.py +14 -0
- csv2ofx-0.33.0/csv2ofx/mappings/exim.py +13 -0
- csv2ofx-0.33.0/csv2ofx/mappings/gls.py +23 -0
- csv2ofx-0.33.0/csv2ofx/mappings/ingdirect.py +20 -0
- csv2ofx-0.33.0/csv2ofx/mappings/ingesp.py +85 -0
- csv2ofx-0.33.0/csv2ofx/mappings/mdb.py +22 -0
- csv2ofx-0.33.0/csv2ofx/mappings/mint.py +23 -0
- csv2ofx-0.33.0/csv2ofx/mappings/mint_extra.py +28 -0
- csv2ofx-0.33.0/csv2ofx/mappings/mint_headerless.py +22 -0
- csv2ofx-0.33.0/csv2ofx/mappings/mintapi.py +30 -0
- csv2ofx-0.33.0/csv2ofx/mappings/msmoneyreport.py +16 -0
- csv2ofx-0.33.0/csv2ofx/mappings/n26.py +34 -0
- csv2ofx-0.33.0/csv2ofx/mappings/outbank.py +23 -0
- csv2ofx-0.33.0/csv2ofx/mappings/payoneer.py +52 -0
- csv2ofx-0.33.0/csv2ofx/mappings/pcmastercard.py +16 -0
- csv2ofx-0.33.0/csv2ofx/mappings/rabobank.py +29 -0
- csv2ofx-0.33.0/csv2ofx/mappings/schwabchecking.py +19 -0
- csv2ofx-0.33.0/csv2ofx/mappings/split_account.py +18 -0
- csv2ofx-0.33.0/csv2ofx/mappings/starling.py +16 -0
- csv2ofx-0.33.0/csv2ofx/mappings/stripe.py +31 -0
- csv2ofx-0.33.0/csv2ofx/mappings/ubs-ch-fr.py +77 -0
- csv2ofx-0.33.0/csv2ofx/mappings/ubs.py +16 -0
- csv2ofx-0.33.0/csv2ofx/mappings/xero.py +14 -0
- csv2ofx-0.33.0/csv2ofx/mappings/yodlee.py +23 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/ofx.py +58 -65
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/qif.py +26 -28
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/utils.py +22 -22
- {csv2ofx-0.32.0 → csv2ofx-0.33.0/csv2ofx.egg-info}/PKG-INFO +49 -52
- csv2ofx-0.33.0/csv2ofx.egg-info/SOURCES.txt +123 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/requires.txt +6 -0
- csv2ofx-0.33.0/data/converted/amazon.ofx +51 -0
- csv2ofx-0.33.0/data/converted/creditunion.qif +45 -0
- csv2ofx-0.33.0/data/converted/default.ofx +111 -0
- csv2ofx-0.33.0/data/converted/default.qif +50 -0
- csv2ofx-0.33.0/data/converted/default_w_splits.ofx +167 -0
- csv2ofx-0.33.0/data/converted/default_w_splits.qif +66 -0
- csv2ofx-0.33.0/data/converted/gls.ofx +43 -0
- csv2ofx-0.33.0/data/converted/ingesp.ofx +115 -0
- csv2ofx-0.33.0/data/converted/mint.ofx +95 -0
- csv2ofx-0.33.0/data/converted/mint.qif +42 -0
- csv2ofx-0.33.0/data/converted/mint_alt.qif +21 -0
- csv2ofx-0.33.0/data/converted/mint_extra.qif +34 -0
- csv2ofx-0.33.0/data/converted/outbank.ofx +67 -0
- csv2ofx-0.33.0/data/converted/payoneer.ofx +55 -0
- csv2ofx-0.33.0/data/converted/pcmastercard.ofx +47 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case1.ofx +75 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case2.ofx +71 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case3.ofx +75 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case4.ofx +75 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case5.ofx +75 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case6.ofx +75 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case7.ofx +53 -0
- csv2ofx-0.33.0/data/converted/schwab-checking-msmoney.ofx +79 -0
- csv2ofx-0.33.0/data/converted/schwab-checking.ofx +75 -0
- csv2ofx-0.33.0/data/converted/stripe-all.ofx +75 -0
- csv2ofx-0.33.0/data/converted/stripe-all.qif +30 -0
- csv2ofx-0.33.0/data/converted/stripe-default.ofx +75 -0
- csv2ofx-0.33.0/data/converted/stripe-default.qif +26 -0
- csv2ofx-0.33.0/data/converted/ubs-ch-fr.qif +25 -0
- csv2ofx-0.33.0/data/converted/xero.qif +64 -0
- csv2ofx-0.33.0/data/example/investment_example.qif +24 -0
- csv2ofx-0.33.0/data/example/transaction_example.ofx +46 -0
- csv2ofx-0.33.0/data/example/transfer_example.ofx +41 -0
- csv2ofx-0.33.0/data/test/amazon.csv +5 -0
- csv2ofx-0.33.0/data/test/capitalone.csv +3 -0
- csv2ofx-0.33.0/data/test/creditunion.csv +1 -0
- csv2ofx-0.33.0/data/test/default.csv +9 -0
- csv2ofx-0.33.0/data/test/gls.csv +2 -0
- csv2ofx-0.33.0/data/test/ingesp.csv +11 -0
- csv2ofx-0.33.0/data/test/mint.csv +1 -0
- csv2ofx-0.33.0/data/test/mint_extra.csv +1 -0
- csv2ofx-0.33.0/data/test/mint_headerless.csv +1 -0
- csv2ofx-0.33.0/data/test/outbank.csv +5 -0
- csv2ofx-0.33.0/data/test/payoneer.csv +3 -0
- csv2ofx-0.33.0/data/test/pcmastercard.csv +3 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case1.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case2.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case3.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case4.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case5.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case6.csv +5 -0
- csv2ofx-0.33.0/data/test/schwab-checking-baltest-case7.csv +3 -0
- csv2ofx-0.33.0/data/test/schwab-checking.csv +5 -0
- csv2ofx-0.33.0/data/test/stripe-all.csv +6 -0
- csv2ofx-0.33.0/data/test/stripe-default.csv +6 -0
- csv2ofx-0.33.0/data/test/ubs-ch-fr_trimmed.csv +4 -0
- csv2ofx-0.33.0/data/test/xero.csv +1 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/pyproject.toml +16 -6
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/tests/test.py +32 -30
- csv2ofx-0.32.0/csv2ofx.egg-info/SOURCES.txt +0 -35
- csv2ofx-0.32.0/dev-requirements.txt +0 -3
- csv2ofx-0.32.0/requirements.txt +0 -3
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/LICENSE +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/dependency_links.txt +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/entry_points.txt +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/top_level.txt +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFX 2.1.1.pdf +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFXAudit.xls +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFX_Message_Support.doc +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_002.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_003.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_004.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_005.html +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/bootstrap.js +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/jquery.js +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/sitecss.css +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/qif-file-format.txt +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/check-stage +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/clean +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/srcdist +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/wheel +0 -0
- {csv2ofx-0.32.0 → csv2ofx-0.33.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: csv2ofx
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.33.0
|
|
4
4
|
Summary: converts a csv file of transactions to an ofx or qif file
|
|
5
5
|
Author-email: Reuben Cummings <reubano@gmail.com>
|
|
6
6
|
Maintainer-email: "Jason R. Coombs" <jaraco@jaraco.com>
|
|
@@ -14,31 +14,38 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
|
14
14
|
Classifier: Environment :: Console
|
|
15
15
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
16
|
Classifier: Intended Audience :: Developers
|
|
17
|
+
Requires-Python: >=3.9
|
|
17
18
|
Description-Content-Type: text/markdown
|
|
18
19
|
License-File: LICENSE
|
|
19
20
|
Requires-Dist: python-dateutil<3.0.0,>=2.7.2
|
|
20
21
|
Requires-Dist: requests<3.0.0,>=2.18.4
|
|
21
22
|
Requires-Dist: meza<0.48.0,>=0.47.0
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pygogo<2.0.0,>=0.13.2; extra == "test"
|
|
25
|
+
Requires-Dist: pytest; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-enabler; extra == "test"
|
|
27
|
+
Requires-Dist: pytest-ruff; extra == "test"
|
|
22
28
|
|
|
23
29
|
# csv2ofx
|
|
24
30
|
|
|
25
|
-
[](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22)
|
|
26
32
|
[](https://pypi.python.org/pypi/csv2ofx)
|
|
27
33
|
[](https://pypi.python.org/pypi/csv2ofx)
|
|
34
|
+
[](https://github.com/astral-sh/ruff)
|
|
28
35
|
|
|
29
36
|
## INTRODUCTION
|
|
30
37
|
|
|
31
|
-
[csv2ofx](http://github.com/reubano/csv2ofx) is a [Python library](#library-examples) and [command line interface program](#cli-examples) that converts CSV files to OFX and QIF files for importing into GnuCash or similar financial accounting programs. csv2ofx has built in support for importing csv files from mint, yoodlee, and xero.
|
|
38
|
+
[csv2ofx](http://github.com/reubano/csv2ofx) is a [Python library](#library-examples) and [command line interface program](#cli-examples) that converts CSV files to OFX and QIF files for importing into GnuCash or Moneydance or similar financial accounting programs. csv2ofx has built in support for importing csv files from mint, yoodlee, and xero.
|
|
32
39
|
|
|
33
40
|
## Requirements
|
|
34
41
|
|
|
35
|
-
csv2ofx
|
|
42
|
+
csv2ofx is pure Python and is [tested](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22) on a number of Pythons and platforms.
|
|
36
43
|
|
|
37
44
|
## INSTALLATION
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
pip install csv2ofx
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
(recommended in a [virtualenv](https://virtualenv.pypa.io/en/latest/))
|
|
42
49
|
|
|
43
50
|
## Usage
|
|
44
51
|
|
|
@@ -105,40 +112,34 @@ positional arguments:
|
|
|
105
112
|
source the source csv file (default: stdin)
|
|
106
113
|
dest the output file (default: stdout)
|
|
107
114
|
|
|
108
|
-
|
|
115
|
+
options:
|
|
109
116
|
-h, --help show this help message and exit
|
|
110
|
-
-a
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
-B BALANCE, --ending-balance BALANCE
|
|
117
|
+
-a, --account TYPE default account type 'CHECKING' for OFX and 'Bank' for QIF.
|
|
118
|
+
-e, --end DATE end date (default: today)
|
|
119
|
+
-B, --ending-balance BALANCE
|
|
114
120
|
ending balance (default: None)
|
|
115
|
-
-l
|
|
121
|
+
-l, --language LANGUAGE
|
|
116
122
|
the language (default: ENG)
|
|
117
|
-
-s
|
|
118
|
-
the start date
|
|
123
|
+
-s, --start DATE the start date
|
|
119
124
|
-y, --dayfirst interpret the first value in ambiguous dates (e.g. 01/05/09) as the day
|
|
120
|
-
-m
|
|
125
|
+
-m, --mapping MAPPING_NAME
|
|
121
126
|
the account mapping (default: default)
|
|
122
|
-
-x
|
|
127
|
+
-x, --custom FILE_PATH
|
|
123
128
|
path to a custom mapping file
|
|
124
|
-
-c
|
|
129
|
+
-c, --collapse FIELD_NAME
|
|
125
130
|
field used to combine transactions within a split for double entry statements
|
|
126
|
-
-C
|
|
127
|
-
|
|
128
|
-
-
|
|
129
|
-
|
|
130
|
-
-R ROWS, --last-row ROWS
|
|
131
|
-
the last row to process (zero based, negative values count from the end)
|
|
132
|
-
-O COLS, --first-col COLS
|
|
133
|
-
the first column to process (zero based)
|
|
131
|
+
-C, --chunksize ROWS number of rows to process at a time (default: 2 ** 14)
|
|
132
|
+
-r, --first-row ROWS the first row to process (zero based)
|
|
133
|
+
-R, --last-row ROWS the last row to process (zero based, negative values count from the end)
|
|
134
|
+
-O, --first-col COLS the first column to process (zero based)
|
|
134
135
|
-L, --list-mappings list the available mappings
|
|
135
136
|
-V, --version show version and exit
|
|
136
137
|
-q, --qif enables 'QIF' output instead of 'OFX'
|
|
137
138
|
-M, --ms-money enables MS Money compatible 'OFX' output
|
|
138
139
|
-o, --overwrite overwrite destination file if it exists
|
|
139
|
-
-D
|
|
140
|
+
-D, --server-date DATE
|
|
140
141
|
OFX server date (default: source file mtime)
|
|
141
|
-
-E
|
|
142
|
+
-E, --encoding ENCODING
|
|
142
143
|
File encoding (default: utf-8)
|
|
143
144
|
-d, --debug display the options and arguments passed to the parser
|
|
144
145
|
-v, --verbose verbose output
|
|
@@ -183,7 +184,7 @@ shipped `utilz/csvtrim` shell script. F.i., with mapping `ubs-ch-fr`:
|
|
|
183
184
|
|
|
184
185
|
### Code modification
|
|
185
186
|
|
|
186
|
-
|
|
187
|
+
To import csv files with field names different from the default, either modify the mapping file or create your own. New mappings must be placed in the `csv2ofx/mappings` folder. The mapping object consists of a dictionary whose keys are OFX/QIF attributes and whose values are functions that should return the corresponding value from a record (csv row). The mapping function will take in a record, e.g.,
|
|
187
188
|
|
|
188
189
|
```python
|
|
189
190
|
{'Account': 'savings 2', 'Date': '1/3/15', 'Amount': 5000}
|
|
@@ -210,7 +211,7 @@ mapping = {
|
|
|
210
211
|
'amount': lambda r: r['Amount'] * 2,
|
|
211
212
|
'first_row': 1,
|
|
212
213
|
'last_row': 10,
|
|
213
|
-
'filter': lambda r: r['Amount'] > 10,
|
|
214
|
+
'filter': lambda r: float(r['Amount']) > 10,
|
|
214
215
|
}
|
|
215
216
|
```
|
|
216
217
|
|
|
@@ -253,54 +254,50 @@ attribute | description | default value | example
|
|
|
253
254
|
`first_row`|the first row to process (zero based)|0|2
|
|
254
255
|
`last_row`|the last row to process (zero based, negative values count from the end)|inf|-2
|
|
255
256
|
`first_col`|the first column to process (zero based)|0|2
|
|
256
|
-
`filter`|keep transactions for which function returns true||lambda tr: tr['amount'] > 10
|
|
257
|
+
`filter`|keep transactions for which function returns true||lambda tr: float(tr['amount']) > 10
|
|
257
258
|
|
|
258
259
|
## Scripts
|
|
259
260
|
|
|
260
|
-
|
|
261
|
+
### Running tests
|
|
261
262
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
pip install -r dev-requirements.txt
|
|
265
|
-
|
|
266
|
-
### Examples
|
|
267
|
-
|
|
268
|
-
*Run python linter and nose tests*
|
|
269
|
-
|
|
270
|
-
```bash
|
|
271
|
-
manage lint
|
|
272
|
-
manage test
|
|
273
|
-
```
|
|
263
|
+
tox
|
|
274
264
|
|
|
275
265
|
## Contributing
|
|
276
266
|
|
|
277
|
-
Please mimic the coding style/conventions used in this repo.
|
|
267
|
+
Please mimic the coding style/conventions used in this repo. When adding new classes or functions, please add the appropriate doc blocks with examples.
|
|
278
268
|
|
|
279
269
|
Ready to contribute? Here's how:
|
|
280
270
|
|
|
281
271
|
1. Fork and clone.
|
|
282
272
|
|
|
283
273
|
```bash
|
|
284
|
-
git clone
|
|
274
|
+
git clone https://github.com/reubano/csv2ofx
|
|
285
275
|
cd csv2ofx
|
|
286
276
|
```
|
|
287
277
|
|
|
288
|
-
2.
|
|
278
|
+
2. Run tox.
|
|
279
|
+
|
|
280
|
+
Either install [tox](https://tox.wiki) or install [pipx](https://pipx.pypa.io) and use it to `pipx run tox`:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
tox
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Tox will run the tests and other checks (linter) in different Python environments. It will create Python environments in `.tox/*` (e.g. `.tox/py313`) and install csv2ofx there. To run in just the main python environment:
|
|
289
287
|
|
|
290
288
|
```bash
|
|
291
|
-
|
|
292
|
-
activate csv2ofx
|
|
293
|
-
python setup.py develop
|
|
294
|
-
pip install -r dev-requirements.txt
|
|
289
|
+
tox -e py
|
|
295
290
|
```
|
|
296
291
|
|
|
292
|
+
Feel free to activate one of those environments or create a separate one.
|
|
293
|
+
|
|
297
294
|
3. Create a branch for local development
|
|
298
295
|
|
|
299
296
|
```bash
|
|
300
297
|
git checkout -b name-of-your-bugfix-or-feature
|
|
301
298
|
```
|
|
302
299
|
|
|
303
|
-
4. Make your changes, run
|
|
300
|
+
4. Make your changes, run tests (see above), and submit a pull request through the GitHub website.
|
|
304
301
|
|
|
305
302
|
### Adding Mappings
|
|
306
303
|
|
|
@@ -309,7 +306,7 @@ How to contribute a mapping:
|
|
|
309
306
|
1. Add the mapping in `csv2ofx/mappings/`
|
|
310
307
|
2. Add a simple example CSV file in `data/test/`.
|
|
311
308
|
3. Add the OFX or QIF file that results from the mapping and example CSV file in `data/converted/`.
|
|
312
|
-
4. Add a `csv2ofx` call for your mapping to the tests in `tests/test.py`, in `PRE_TESTS`.
|
|
309
|
+
4. Add a `csv2ofx` call for your mapping to the tests in `tests/test.py`, in `PRE_TESTS`. When adding an OFX (not QIF) converted file, pay attention to the `-e` (end date) and `-D` (server date) arguments in the test- otherwise tests may pass locally but fail on the build server.
|
|
313
310
|
5. Ensure your test succeeds (see above).
|
|
314
311
|
|
|
315
312
|
## License
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
# csv2ofx
|
|
2
2
|
|
|
3
|
-
[](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22)
|
|
4
4
|
[](https://pypi.python.org/pypi/csv2ofx)
|
|
5
5
|
[](https://pypi.python.org/pypi/csv2ofx)
|
|
6
|
+
[](https://github.com/astral-sh/ruff)
|
|
6
7
|
|
|
7
8
|
## INTRODUCTION
|
|
8
9
|
|
|
9
|
-
[csv2ofx](http://github.com/reubano/csv2ofx) is a [Python library](#library-examples) and [command line interface program](#cli-examples) that converts CSV files to OFX and QIF files for importing into GnuCash or similar financial accounting programs. csv2ofx has built in support for importing csv files from mint, yoodlee, and xero.
|
|
10
|
+
[csv2ofx](http://github.com/reubano/csv2ofx) is a [Python library](#library-examples) and [command line interface program](#cli-examples) that converts CSV files to OFX and QIF files for importing into GnuCash or Moneydance or similar financial accounting programs. csv2ofx has built in support for importing csv files from mint, yoodlee, and xero.
|
|
10
11
|
|
|
11
12
|
## Requirements
|
|
12
13
|
|
|
13
|
-
csv2ofx
|
|
14
|
+
csv2ofx is pure Python and is [tested](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22) on a number of Pythons and platforms.
|
|
14
15
|
|
|
15
16
|
## INSTALLATION
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
pip install csv2ofx
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
(recommended in a [virtualenv](https://virtualenv.pypa.io/en/latest/))
|
|
20
21
|
|
|
21
22
|
## Usage
|
|
22
23
|
|
|
@@ -83,40 +84,34 @@ positional arguments:
|
|
|
83
84
|
source the source csv file (default: stdin)
|
|
84
85
|
dest the output file (default: stdout)
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
options:
|
|
87
88
|
-h, --help show this help message and exit
|
|
88
|
-
-a
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
-B BALANCE, --ending-balance BALANCE
|
|
89
|
+
-a, --account TYPE default account type 'CHECKING' for OFX and 'Bank' for QIF.
|
|
90
|
+
-e, --end DATE end date (default: today)
|
|
91
|
+
-B, --ending-balance BALANCE
|
|
92
92
|
ending balance (default: None)
|
|
93
|
-
-l
|
|
93
|
+
-l, --language LANGUAGE
|
|
94
94
|
the language (default: ENG)
|
|
95
|
-
-s
|
|
96
|
-
the start date
|
|
95
|
+
-s, --start DATE the start date
|
|
97
96
|
-y, --dayfirst interpret the first value in ambiguous dates (e.g. 01/05/09) as the day
|
|
98
|
-
-m
|
|
97
|
+
-m, --mapping MAPPING_NAME
|
|
99
98
|
the account mapping (default: default)
|
|
100
|
-
-x
|
|
99
|
+
-x, --custom FILE_PATH
|
|
101
100
|
path to a custom mapping file
|
|
102
|
-
-c
|
|
101
|
+
-c, --collapse FIELD_NAME
|
|
103
102
|
field used to combine transactions within a split for double entry statements
|
|
104
|
-
-C
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
108
|
-
-R ROWS, --last-row ROWS
|
|
109
|
-
the last row to process (zero based, negative values count from the end)
|
|
110
|
-
-O COLS, --first-col COLS
|
|
111
|
-
the first column to process (zero based)
|
|
103
|
+
-C, --chunksize ROWS number of rows to process at a time (default: 2 ** 14)
|
|
104
|
+
-r, --first-row ROWS the first row to process (zero based)
|
|
105
|
+
-R, --last-row ROWS the last row to process (zero based, negative values count from the end)
|
|
106
|
+
-O, --first-col COLS the first column to process (zero based)
|
|
112
107
|
-L, --list-mappings list the available mappings
|
|
113
108
|
-V, --version show version and exit
|
|
114
109
|
-q, --qif enables 'QIF' output instead of 'OFX'
|
|
115
110
|
-M, --ms-money enables MS Money compatible 'OFX' output
|
|
116
111
|
-o, --overwrite overwrite destination file if it exists
|
|
117
|
-
-D
|
|
112
|
+
-D, --server-date DATE
|
|
118
113
|
OFX server date (default: source file mtime)
|
|
119
|
-
-E
|
|
114
|
+
-E, --encoding ENCODING
|
|
120
115
|
File encoding (default: utf-8)
|
|
121
116
|
-d, --debug display the options and arguments passed to the parser
|
|
122
117
|
-v, --verbose verbose output
|
|
@@ -161,7 +156,7 @@ shipped `utilz/csvtrim` shell script. F.i., with mapping `ubs-ch-fr`:
|
|
|
161
156
|
|
|
162
157
|
### Code modification
|
|
163
158
|
|
|
164
|
-
|
|
159
|
+
To import csv files with field names different from the default, either modify the mapping file or create your own. New mappings must be placed in the `csv2ofx/mappings` folder. The mapping object consists of a dictionary whose keys are OFX/QIF attributes and whose values are functions that should return the corresponding value from a record (csv row). The mapping function will take in a record, e.g.,
|
|
165
160
|
|
|
166
161
|
```python
|
|
167
162
|
{'Account': 'savings 2', 'Date': '1/3/15', 'Amount': 5000}
|
|
@@ -188,7 +183,7 @@ mapping = {
|
|
|
188
183
|
'amount': lambda r: r['Amount'] * 2,
|
|
189
184
|
'first_row': 1,
|
|
190
185
|
'last_row': 10,
|
|
191
|
-
'filter': lambda r: r['Amount'] > 10,
|
|
186
|
+
'filter': lambda r: float(r['Amount']) > 10,
|
|
192
187
|
}
|
|
193
188
|
```
|
|
194
189
|
|
|
@@ -231,54 +226,50 @@ attribute | description | default value | example
|
|
|
231
226
|
`first_row`|the first row to process (zero based)|0|2
|
|
232
227
|
`last_row`|the last row to process (zero based, negative values count from the end)|inf|-2
|
|
233
228
|
`first_col`|the first column to process (zero based)|0|2
|
|
234
|
-
`filter`|keep transactions for which function returns true||lambda tr: tr['amount'] > 10
|
|
229
|
+
`filter`|keep transactions for which function returns true||lambda tr: float(tr['amount']) > 10
|
|
235
230
|
|
|
236
231
|
## Scripts
|
|
237
232
|
|
|
238
|
-
|
|
233
|
+
### Running tests
|
|
239
234
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
pip install -r dev-requirements.txt
|
|
243
|
-
|
|
244
|
-
### Examples
|
|
245
|
-
|
|
246
|
-
*Run python linter and nose tests*
|
|
247
|
-
|
|
248
|
-
```bash
|
|
249
|
-
manage lint
|
|
250
|
-
manage test
|
|
251
|
-
```
|
|
235
|
+
tox
|
|
252
236
|
|
|
253
237
|
## Contributing
|
|
254
238
|
|
|
255
|
-
Please mimic the coding style/conventions used in this repo.
|
|
239
|
+
Please mimic the coding style/conventions used in this repo. When adding new classes or functions, please add the appropriate doc blocks with examples.
|
|
256
240
|
|
|
257
241
|
Ready to contribute? Here's how:
|
|
258
242
|
|
|
259
243
|
1. Fork and clone.
|
|
260
244
|
|
|
261
245
|
```bash
|
|
262
|
-
git clone
|
|
246
|
+
git clone https://github.com/reubano/csv2ofx
|
|
263
247
|
cd csv2ofx
|
|
264
248
|
```
|
|
265
249
|
|
|
266
|
-
2.
|
|
250
|
+
2. Run tox.
|
|
251
|
+
|
|
252
|
+
Either install [tox](https://tox.wiki) or install [pipx](https://pipx.pypa.io) and use it to `pipx run tox`:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
tox
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Tox will run the tests and other checks (linter) in different Python environments. It will create Python environments in `.tox/*` (e.g. `.tox/py313`) and install csv2ofx there. To run in just the main python environment:
|
|
267
259
|
|
|
268
260
|
```bash
|
|
269
|
-
|
|
270
|
-
activate csv2ofx
|
|
271
|
-
python setup.py develop
|
|
272
|
-
pip install -r dev-requirements.txt
|
|
261
|
+
tox -e py
|
|
273
262
|
```
|
|
274
263
|
|
|
264
|
+
Feel free to activate one of those environments or create a separate one.
|
|
265
|
+
|
|
275
266
|
3. Create a branch for local development
|
|
276
267
|
|
|
277
268
|
```bash
|
|
278
269
|
git checkout -b name-of-your-bugfix-or-feature
|
|
279
270
|
```
|
|
280
271
|
|
|
281
|
-
4. Make your changes, run
|
|
272
|
+
4. Make your changes, run tests (see above), and submit a pull request through the GitHub website.
|
|
282
273
|
|
|
283
274
|
### Adding Mappings
|
|
284
275
|
|
|
@@ -287,7 +278,7 @@ How to contribute a mapping:
|
|
|
287
278
|
1. Add the mapping in `csv2ofx/mappings/`
|
|
288
279
|
2. Add a simple example CSV file in `data/test/`.
|
|
289
280
|
3. Add the OFX or QIF file that results from the mapping and example CSV file in `data/converted/`.
|
|
290
|
-
4. Add a `csv2ofx` call for your mapping to the tests in `tests/test.py`, in `PRE_TESTS`.
|
|
281
|
+
4. Add a `csv2ofx` call for your mapping to the tests in `tests/test.py`, in `PRE_TESTS`. When adding an OFX (not QIF) converted file, pay attention to the `-e` (end date) and `-D` (server date) arguments in the test- otherwise tests may pass locally but fail on the build server.
|
|
291
282
|
5. Ensure your test succeeds (see above).
|
|
292
283
|
|
|
293
284
|
## License
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
2
|
# vim: sw=4:ts=4:expandtab
|
|
4
3
|
|
|
5
4
|
"""
|
|
@@ -18,32 +17,20 @@ Attributes:
|
|
|
18
17
|
"""
|
|
19
18
|
|
|
20
19
|
import hashlib
|
|
21
|
-
import itertools as it
|
|
22
|
-
|
|
23
|
-
from functools import partial
|
|
24
20
|
from datetime import datetime as dt
|
|
25
|
-
from operator import itemgetter
|
|
26
21
|
from decimal import Decimal
|
|
22
|
+
from functools import partial
|
|
23
|
+
from itertools import filterfalse
|
|
27
24
|
|
|
28
|
-
from builtins import *
|
|
29
|
-
from six.moves import filterfalse
|
|
30
|
-
from meza.process import merge, group
|
|
31
25
|
from dateutil.parser import parse
|
|
26
|
+
from meza.process import group, merge
|
|
32
27
|
|
|
33
28
|
from . import utils
|
|
34
29
|
|
|
35
|
-
__title__ = "csv2ofx"
|
|
36
|
-
__package_name__ = "csv2ofx"
|
|
37
|
-
__author__ = "Reuben Cummings"
|
|
38
|
-
__description__ = "converts a csv file of transactions to an ofx or qif file"
|
|
39
|
-
__email__ = "reubano@gmail.com"
|
|
40
|
-
__version__ = "0.32.0"
|
|
41
|
-
__license__ = "MIT"
|
|
42
|
-
__copyright__ = "Copyright 2015 Reuben Cummings"
|
|
43
|
-
|
|
44
30
|
|
|
45
31
|
# pylint: disable=invalid-name
|
|
46
|
-
|
|
32
|
+
def md5(content):
|
|
33
|
+
return hashlib.md5(content.encode("utf-8")).hexdigest()
|
|
47
34
|
|
|
48
35
|
|
|
49
36
|
class BalanceError(Exception):
|
|
@@ -52,7 +39,7 @@ class BalanceError(Exception):
|
|
|
52
39
|
pass
|
|
53
40
|
|
|
54
41
|
|
|
55
|
-
class Content
|
|
42
|
+
class Content: # pylint: disable=too-many-instance-attributes
|
|
56
43
|
"""A transaction holding object"""
|
|
57
44
|
|
|
58
45
|
def __init__(self, mapping=None, **kwargs):
|
|
@@ -250,7 +237,7 @@ class Content(object): # pylint: disable=too-many-instance-attributes
|
|
|
250
237
|
payee = self.get("payee", trxn)
|
|
251
238
|
desc = self.get("desc", trxn)
|
|
252
239
|
notes = self.get("notes", trxn)
|
|
253
|
-
memo = "
|
|
240
|
+
memo = f"{desc} {notes}" if desc and notes else desc or notes
|
|
254
241
|
check_num = self.get("check_num", trxn)
|
|
255
242
|
details = "".join(filter(None, [date, raw_amount, payee, memo]))
|
|
256
243
|
category = self.get("category", trxn, "")
|
|
@@ -307,7 +294,10 @@ class Content(object): # pylint: disable=too-many-instance-attributes
|
|
|
307
294
|
if self.is_split and collapse:
|
|
308
295
|
# group transactions by `collapse` field and sum the amounts
|
|
309
296
|
byaccount = group(transactions, collapse)
|
|
310
|
-
|
|
297
|
+
|
|
298
|
+
def oprtn(values):
|
|
299
|
+
return sum(map(utils.convert_amount, values))
|
|
300
|
+
|
|
311
301
|
merger = partial(merge, pred=self.amount, op=oprtn)
|
|
312
302
|
trxns = [merger(dicts) for _, dicts in byaccount]
|
|
313
303
|
else:
|
|
@@ -336,6 +326,8 @@ class Content(object): # pylint: disable=too-many-instance-attributes
|
|
|
336
326
|
main_pos = 0
|
|
337
327
|
|
|
338
328
|
# pylint: disable=cell-var-from-loop
|
|
339
|
-
keyfunc
|
|
329
|
+
def keyfunc(enum):
|
|
330
|
+
return enum[0] != main_pos
|
|
331
|
+
|
|
340
332
|
sorted_trxns = sorted(enumerate(filtered_trxns), key=keyfunc)
|
|
341
333
|
yield (grp, main_pos, sorted_trxns)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
2
|
# vim: sw=4:ts=4:expandtab
|
|
4
3
|
|
|
5
4
|
"""
|
|
@@ -17,35 +16,33 @@ Attributes:
|
|
|
17
16
|
ENCODING (str): Default file encoding.
|
|
18
17
|
"""
|
|
19
18
|
|
|
20
|
-
import time
|
|
21
19
|
import itertools as it
|
|
20
|
+
import time
|
|
22
21
|
import traceback
|
|
23
|
-
|
|
24
|
-
from
|
|
22
|
+
from argparse import ArgumentParser, RawTextHelpFormatter
|
|
23
|
+
from datetime import datetime as dt
|
|
25
24
|
from importlib import import_module, util
|
|
26
|
-
from
|
|
25
|
+
from math import inf
|
|
27
26
|
from operator import itemgetter
|
|
28
27
|
from os import path as p
|
|
29
|
-
from
|
|
30
|
-
from datetime import datetime as dt
|
|
31
|
-
from argparse import RawTextHelpFormatter, ArgumentParser
|
|
28
|
+
from pkgutil import iter_modules
|
|
32
29
|
from pprint import pprint
|
|
33
|
-
from
|
|
30
|
+
from sys import exit, stdin, stdout
|
|
34
31
|
|
|
35
32
|
try:
|
|
36
33
|
FileNotFoundError
|
|
37
34
|
except NameError:
|
|
38
35
|
FileNotFoundError = IOError
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
import builtins
|
|
38
|
+
|
|
41
39
|
from dateutil.parser import parse
|
|
42
|
-
from meza.io import
|
|
40
|
+
from meza.io import IterStringIO, read_csv, write
|
|
43
41
|
|
|
44
42
|
from . import BalanceError, utils
|
|
45
43
|
from .ofx import OFX
|
|
46
44
|
from .qif import QIF
|
|
47
45
|
|
|
48
|
-
|
|
49
46
|
parser = ArgumentParser( # pylint: disable=invalid-name
|
|
50
47
|
description="description: csv2ofx converts a csv file to ofx and qif",
|
|
51
48
|
prog="csv2ofx",
|
|
@@ -209,7 +206,7 @@ def run(): # noqa: C901
|
|
|
209
206
|
if args.version:
|
|
210
207
|
from . import __version__ as version
|
|
211
208
|
|
|
212
|
-
print("v
|
|
209
|
+
print(f"v{version}")
|
|
213
210
|
exit(0)
|
|
214
211
|
|
|
215
212
|
if args.list_mappings:
|
|
@@ -222,7 +219,7 @@ def run(): # noqa: C901
|
|
|
222
219
|
module = util.module_from_spec(spec)
|
|
223
220
|
spec.loader.exec_module(module)
|
|
224
221
|
else:
|
|
225
|
-
module = import_module("csv2ofx.mappings
|
|
222
|
+
module = import_module(f"csv2ofx.mappings.{args.mapping}")
|
|
226
223
|
|
|
227
224
|
mapping = module.mapping
|
|
228
225
|
|
|
@@ -234,7 +231,9 @@ def run(): # noqa: C901
|
|
|
234
231
|
}
|
|
235
232
|
|
|
236
233
|
cont = QIF(mapping, **okwargs) if args.qif else OFX(mapping, **okwargs)
|
|
237
|
-
source =
|
|
234
|
+
source = (
|
|
235
|
+
builtins.open(args.source, encoding=args.encoding) if args.source else stdin
|
|
236
|
+
)
|
|
238
237
|
|
|
239
238
|
ckwargs = {
|
|
240
239
|
"has_header": cont.has_header,
|
|
@@ -276,14 +275,16 @@ def run(): # noqa: C901
|
|
|
276
275
|
source.close()
|
|
277
276
|
exit(err)
|
|
278
277
|
|
|
279
|
-
dest =
|
|
278
|
+
dest = (
|
|
279
|
+
builtins.open(args.dest, "w", encoding=args.encoding) if args.dest else stdout
|
|
280
|
+
)
|
|
280
281
|
|
|
281
282
|
try:
|
|
282
283
|
res = write(dest, IterStringIO(content), **kwargs)
|
|
283
284
|
except KeyError as err:
|
|
284
|
-
msg = "Field
|
|
285
|
+
msg = f"Field {err} is missing from file. Check `mapping` option."
|
|
285
286
|
except TypeError as err:
|
|
286
|
-
msg = "No data to write.
|
|
287
|
+
msg = f"No data to write. {str(err)}. "
|
|
287
288
|
|
|
288
289
|
if args.collapse:
|
|
289
290
|
msg += "Check `start` and `end` options."
|
|
@@ -291,10 +292,10 @@ def run(): # noqa: C901
|
|
|
291
292
|
msg += "Try again with `-c` option."
|
|
292
293
|
except ValueError as err:
|
|
293
294
|
# csv2ofx called with no arguments or broken mapping
|
|
294
|
-
msg = "Possible mapping problem:
|
|
295
|
+
msg = f"Possible mapping problem: {str(err)}. "
|
|
295
296
|
parser.print_help()
|
|
296
297
|
except BalanceError as err:
|
|
297
|
-
msg = "
|
|
298
|
+
msg = f"{err}. Try again with `--ending-balance` option."
|
|
298
299
|
except Exception: # pylint: disable=broad-except
|
|
299
300
|
msg = 1
|
|
300
301
|
traceback.print_exc()
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from operator import itemgetter
|
|
2
|
+
|
|
3
|
+
mapping = {
|
|
4
|
+
"has_header": False,
|
|
5
|
+
"delimiter": "\t",
|
|
6
|
+
"bank": "ABN Amro",
|
|
7
|
+
"currency": itemgetter("field_1"),
|
|
8
|
+
"account": itemgetter("field_0"),
|
|
9
|
+
"date": itemgetter("field_2"),
|
|
10
|
+
"amount": itemgetter("field_6"),
|
|
11
|
+
"payee": itemgetter("field_7"),
|
|
12
|
+
}
|