csv2ofx 0.32.0__tar.gz → 0.33.1__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.
Files changed (129) hide show
  1. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/MANIFEST.in +1 -1
  2. {csv2ofx-0.32.0/csv2ofx.egg-info → csv2ofx-0.33.1}/PKG-INFO +47 -54
  3. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/README.md +39 -52
  4. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx/__init__.py +34 -34
  5. csv2ofx-0.33.1/csv2ofx/__main__.py +3 -0
  6. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx/main.py +21 -20
  7. csv2ofx-0.33.1/csv2ofx/mappings/__init__.py +6 -0
  8. csv2ofx-0.33.1/csv2ofx/mappings/abnamro.py +12 -0
  9. csv2ofx-0.33.1/csv2ofx/mappings/amazon.py +68 -0
  10. csv2ofx-0.33.1/csv2ofx/mappings/boursorama.py +17 -0
  11. csv2ofx-0.33.1/csv2ofx/mappings/capitalone.py +15 -0
  12. csv2ofx-0.33.1/csv2ofx/mappings/creditunion.py +14 -0
  13. csv2ofx-0.33.1/csv2ofx/mappings/custom.py +21 -0
  14. csv2ofx-0.33.1/csv2ofx/mappings/default.py +17 -0
  15. csv2ofx-0.33.1/csv2ofx/mappings/eqbank.py +14 -0
  16. csv2ofx-0.33.1/csv2ofx/mappings/exim.py +13 -0
  17. csv2ofx-0.33.1/csv2ofx/mappings/gls.py +23 -0
  18. csv2ofx-0.33.1/csv2ofx/mappings/ingdirect.py +20 -0
  19. csv2ofx-0.33.1/csv2ofx/mappings/ingesp.py +85 -0
  20. csv2ofx-0.33.1/csv2ofx/mappings/mdb.py +22 -0
  21. csv2ofx-0.33.1/csv2ofx/mappings/mint.py +23 -0
  22. csv2ofx-0.33.1/csv2ofx/mappings/mint_extra.py +28 -0
  23. csv2ofx-0.33.1/csv2ofx/mappings/mint_headerless.py +22 -0
  24. csv2ofx-0.33.1/csv2ofx/mappings/mintapi.py +30 -0
  25. csv2ofx-0.33.1/csv2ofx/mappings/msmoneyreport.py +16 -0
  26. csv2ofx-0.33.1/csv2ofx/mappings/n26.py +34 -0
  27. csv2ofx-0.33.1/csv2ofx/mappings/outbank.py +23 -0
  28. csv2ofx-0.33.1/csv2ofx/mappings/payoneer.py +52 -0
  29. csv2ofx-0.33.1/csv2ofx/mappings/pcmastercard.py +16 -0
  30. csv2ofx-0.33.1/csv2ofx/mappings/rabobank.py +29 -0
  31. csv2ofx-0.33.1/csv2ofx/mappings/schwabchecking.py +19 -0
  32. csv2ofx-0.33.1/csv2ofx/mappings/split_account.py +18 -0
  33. csv2ofx-0.33.1/csv2ofx/mappings/starling.py +16 -0
  34. csv2ofx-0.33.1/csv2ofx/mappings/stripe.py +31 -0
  35. csv2ofx-0.33.1/csv2ofx/mappings/ubs-ch-fr.py +77 -0
  36. csv2ofx-0.33.1/csv2ofx/mappings/ubs.py +16 -0
  37. csv2ofx-0.33.1/csv2ofx/mappings/xero.py +14 -0
  38. csv2ofx-0.33.1/csv2ofx/mappings/yodlee.py +23 -0
  39. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx/ofx.py +58 -65
  40. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx/qif.py +30 -28
  41. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx/utils.py +22 -22
  42. {csv2ofx-0.32.0 → csv2ofx-0.33.1/csv2ofx.egg-info}/PKG-INFO +47 -54
  43. csv2ofx-0.33.1/csv2ofx.egg-info/SOURCES.txt +123 -0
  44. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx.egg-info/requires.txt +5 -0
  45. csv2ofx-0.33.1/data/converted/amazon.ofx +51 -0
  46. csv2ofx-0.33.1/data/converted/creditunion.qif +45 -0
  47. csv2ofx-0.33.1/data/converted/default.ofx +111 -0
  48. csv2ofx-0.33.1/data/converted/default.qif +50 -0
  49. csv2ofx-0.33.1/data/converted/default_w_splits.ofx +167 -0
  50. csv2ofx-0.33.1/data/converted/default_w_splits.qif +66 -0
  51. csv2ofx-0.33.1/data/converted/gls.ofx +43 -0
  52. csv2ofx-0.33.1/data/converted/ingesp.ofx +115 -0
  53. csv2ofx-0.33.1/data/converted/mint.ofx +95 -0
  54. csv2ofx-0.33.1/data/converted/mint.qif +42 -0
  55. csv2ofx-0.33.1/data/converted/mint_alt.qif +21 -0
  56. csv2ofx-0.33.1/data/converted/mint_extra.qif +34 -0
  57. csv2ofx-0.33.1/data/converted/outbank.ofx +67 -0
  58. csv2ofx-0.33.1/data/converted/payoneer.ofx +55 -0
  59. csv2ofx-0.33.1/data/converted/pcmastercard.ofx +47 -0
  60. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case1.ofx +75 -0
  61. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case2.ofx +71 -0
  62. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case3.ofx +75 -0
  63. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case4.ofx +75 -0
  64. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case5.ofx +75 -0
  65. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case6.ofx +75 -0
  66. csv2ofx-0.33.1/data/converted/schwab-checking-baltest-case7.ofx +53 -0
  67. csv2ofx-0.33.1/data/converted/schwab-checking-msmoney.ofx +79 -0
  68. csv2ofx-0.33.1/data/converted/schwab-checking.ofx +75 -0
  69. csv2ofx-0.33.1/data/converted/stripe-all.ofx +75 -0
  70. csv2ofx-0.33.1/data/converted/stripe-all.qif +30 -0
  71. csv2ofx-0.33.1/data/converted/stripe-default.ofx +75 -0
  72. csv2ofx-0.33.1/data/converted/stripe-default.qif +26 -0
  73. csv2ofx-0.33.1/data/converted/ubs-ch-fr.qif +25 -0
  74. csv2ofx-0.33.1/data/converted/xero.qif +64 -0
  75. csv2ofx-0.33.1/data/example/investment_example.qif +24 -0
  76. csv2ofx-0.33.1/data/example/transaction_example.ofx +46 -0
  77. csv2ofx-0.33.1/data/example/transfer_example.ofx +41 -0
  78. csv2ofx-0.33.1/data/test/amazon.csv +7 -0
  79. csv2ofx-0.33.1/data/test/capitalone.csv +3 -0
  80. csv2ofx-0.33.1/data/test/creditunion.csv +1 -0
  81. csv2ofx-0.33.1/data/test/default.csv +9 -0
  82. csv2ofx-0.33.1/data/test/gls.csv +2 -0
  83. csv2ofx-0.33.1/data/test/ingesp.csv +11 -0
  84. csv2ofx-0.33.1/data/test/mint.csv +1 -0
  85. csv2ofx-0.33.1/data/test/mint_extra.csv +1 -0
  86. csv2ofx-0.33.1/data/test/mint_headerless.csv +1 -0
  87. csv2ofx-0.33.1/data/test/outbank.csv +5 -0
  88. csv2ofx-0.33.1/data/test/payoneer.csv +3 -0
  89. csv2ofx-0.33.1/data/test/pcmastercard.csv +3 -0
  90. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case1.csv +5 -0
  91. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case2.csv +5 -0
  92. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case3.csv +5 -0
  93. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case4.csv +5 -0
  94. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case5.csv +5 -0
  95. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case6.csv +5 -0
  96. csv2ofx-0.33.1/data/test/schwab-checking-baltest-case7.csv +3 -0
  97. csv2ofx-0.33.1/data/test/schwab-checking.csv +5 -0
  98. csv2ofx-0.33.1/data/test/stripe-all.csv +6 -0
  99. csv2ofx-0.33.1/data/test/stripe-default.csv +6 -0
  100. csv2ofx-0.33.1/data/test/ubs-ch-fr_trimmed.csv +4 -0
  101. csv2ofx-0.33.1/data/test/xero.csv +1 -0
  102. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/pyproject.toml +15 -6
  103. csv2ofx-0.33.1/tests/test_cli.py +156 -0
  104. csv2ofx-0.32.0/csv2ofx.egg-info/SOURCES.txt +0 -35
  105. csv2ofx-0.32.0/dev-requirements.txt +0 -3
  106. csv2ofx-0.32.0/requirements.txt +0 -3
  107. csv2ofx-0.32.0/tests/test.py +0 -220
  108. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/LICENSE +0 -0
  109. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx.egg-info/dependency_links.txt +0 -0
  110. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx.egg-info/entry_points.txt +0 -0
  111. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/csv2ofx.egg-info/top_level.txt +0 -0
  112. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/OFX 2.1.1.pdf +0 -0
  113. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/OFXAudit.xls +0 -0
  114. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/OFX_Message_Support.doc +0 -0
  115. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification.html +0 -0
  116. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/a.html +0 -0
  117. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/a_002.html +0 -0
  118. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/a_003.html +0 -0
  119. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/a_004.html +0 -0
  120. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/a_005.html +0 -0
  121. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/bootstrap.js +0 -0
  122. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/jquery.js +0 -0
  123. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/QIF Specification_files/sitecss.css +0 -0
  124. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/docs/qif-file-format.txt +0 -0
  125. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/helpers/check-stage +0 -0
  126. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/helpers/clean +0 -0
  127. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/helpers/srcdist +0 -0
  128. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/helpers/wheel +0 -0
  129. {csv2ofx-0.32.0 → csv2ofx-0.33.1}/setup.cfg +0 -0
@@ -1,4 +1,4 @@
1
- recursive-include csv2ofx/data *
1
+ recursive-include data *
2
2
  recursive-include tests *
3
3
  recursive-include helpers *
4
4
  recursive-include docs *
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: csv2ofx
3
- Version: 0.32.0
3
+ Version: 0.33.1
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: pytest; extra == "test"
25
+ Requires-Dist: pytest-enabler; extra == "test"
26
+ Requires-Dist: pytest-ruff; extra == "test"
27
+ Dynamic: license-file
22
28
 
23
29
  # csv2ofx
24
30
 
25
- [![GHA](https://github.com/PROJECT_PATH/actions/workflows/main.yml/badge.svg)](https://github.com/PROJECT_PATH/actions?query=workflow%3A%22tests%22)
31
+ [![GHA](https://github.com/reubano/csv2ofx/actions/workflows/main.yml/badge.svg)](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22)
26
32
  [![versions](https://img.shields.io/pypi/pyversions/csv2ofx.svg)](https://pypi.python.org/pypi/csv2ofx)
27
33
  [![pypi](https://img.shields.io/pypi/v/csv2ofx.svg)](https://pypi.python.org/pypi/csv2ofx)
34
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](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 has been tested and is known to work on Python 3.7, 3.8, and 3.9; and PyPy3.7.
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
- (You are using a [virtualenv](http://www.virtualenv.org/en/latest/index.html), right?)
46
+ pip install csv2ofx
40
47
 
41
- sudo pip install csv2ofx
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
- optional arguments:
115
+ options:
109
116
  -h, --help show this help message and exit
110
- -a TYPE, --account TYPE
111
- default account type 'CHECKING' for OFX and 'Bank' for QIF.
112
- -e DATE, --end DATE end date (default: today)
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 LANGUAGE, --language LANGUAGE
121
+ -l, --language LANGUAGE
116
122
  the language (default: ENG)
117
- -s DATE, --start DATE
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 MAPPING_NAME, --mapping MAPPING_NAME
125
+ -m, --mapping MAPPING_NAME
121
126
  the account mapping (default: default)
122
- -x FILE_PATH, --custom FILE_PATH
127
+ -x, --custom FILE_PATH
123
128
  path to a custom mapping file
124
- -c FIELD_NAME, --collapse FIELD_NAME
129
+ -c, --collapse FIELD_NAME
125
130
  field used to combine transactions within a split for double entry statements
126
- -C ROWS, --chunksize ROWS
127
- number of rows to process at a time (default: 2 ** 14)
128
- -r ROWS, --first-row ROWS
129
- the first row to process (zero based)
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 DATE, --server-date DATE
140
+ -D, --server-date DATE
140
141
  OFX server date (default: source file mtime)
141
- -E ENCODING, --encoding ENCODING
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
- If you would like to import csv files with field names different from the default, you can modify the mapping file or create your own. New mappings must be placed in the `csv2ofx/mappings` folder (otherwise you must use the ). The mapping object consists of a dictionary whose keys are OFX/QIF attributes and whose values are functions which should return the corresponding value from a record (csv row). The mapping function will take in a record, e.g.,
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,46 @@ 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
- csv2ofx comes with a built in task manager `manage.py`.
261
+ ### Running tests
261
262
 
262
- ### Setup
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. If you add new classes or functions, please add the appropriate doc blocks with examples. Also, make sure the python linter and nose tests pass.
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 git@github.com:<your_username>/csv2ofx.git
274
+ git clone https://github.com/reubano/csv2ofx
285
275
  cd csv2ofx
286
276
  ```
287
277
 
288
- 2. Setup a new [virtualenv](http://www.virtualenv.org/en/latest/index.html)
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`:
289
281
 
290
282
  ```bash
291
- mkvirtualenv -i pkutils csv2ofx
292
- activate csv2ofx
293
- python setup.py develop
294
- pip install -r dev-requirements.txt
283
+ tox
295
284
  ```
296
285
 
286
+ Tox will run the tests and other checks (linter) in different Python environments. It will create a Python environment in `.tox/py` and install csv2ofx there.
287
+
288
+ Feel free to activate that environment or create a separate one.
289
+
297
290
  3. Create a branch for local development
298
291
 
299
292
  ```bash
300
293
  git checkout -b name-of-your-bugfix-or-feature
301
294
  ```
302
295
 
303
- 4. Make your changes, run linter and tests (see above), and submit a pull request through the GitHub website.
296
+ 4. Make your changes, run tests (see above), and submit a pull request through the GitHub website.
304
297
 
305
298
  ### Adding Mappings
306
299
 
@@ -309,8 +302,8 @@ How to contribute a mapping:
309
302
  1. Add the mapping in `csv2ofx/mappings/`
310
303
  2. Add a simple example CSV file in `data/test/`.
311
304
  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`. If you added 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 on your workstation and fail on the build server.
313
- 5. Ensure your test succeeds (see above).
305
+ 4. Add a `csv2ofx` call for your mapping to the tests in `tests/test_cli.py`, in `samples`. 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.
306
+ 5. Ensure the test succeeds (see above).
314
307
 
315
308
  ## License
316
309
 
@@ -1,22 +1,23 @@
1
1
  # csv2ofx
2
2
 
3
- [![GHA](https://github.com/PROJECT_PATH/actions/workflows/main.yml/badge.svg)](https://github.com/PROJECT_PATH/actions?query=workflow%3A%22tests%22)
3
+ [![GHA](https://github.com/reubano/csv2ofx/actions/workflows/main.yml/badge.svg)](https://github.com/reubano/csv2ofx/actions?query=workflow%3A%22tests%22)
4
4
  [![versions](https://img.shields.io/pypi/pyversions/csv2ofx.svg)](https://pypi.python.org/pypi/csv2ofx)
5
5
  [![pypi](https://img.shields.io/pypi/v/csv2ofx.svg)](https://pypi.python.org/pypi/csv2ofx)
6
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](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 has been tested and is known to work on Python 3.7, 3.8, and 3.9; and PyPy3.7.
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
- (You are using a [virtualenv](http://www.virtualenv.org/en/latest/index.html), right?)
18
+ pip install csv2ofx
18
19
 
19
- sudo pip install csv2ofx
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
- optional arguments:
87
+ options:
87
88
  -h, --help show this help message and exit
88
- -a TYPE, --account TYPE
89
- default account type 'CHECKING' for OFX and 'Bank' for QIF.
90
- -e DATE, --end DATE end date (default: today)
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 LANGUAGE, --language LANGUAGE
93
+ -l, --language LANGUAGE
94
94
  the language (default: ENG)
95
- -s DATE, --start DATE
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 MAPPING_NAME, --mapping MAPPING_NAME
97
+ -m, --mapping MAPPING_NAME
99
98
  the account mapping (default: default)
100
- -x FILE_PATH, --custom FILE_PATH
99
+ -x, --custom FILE_PATH
101
100
  path to a custom mapping file
102
- -c FIELD_NAME, --collapse FIELD_NAME
101
+ -c, --collapse FIELD_NAME
103
102
  field used to combine transactions within a split for double entry statements
104
- -C ROWS, --chunksize ROWS
105
- number of rows to process at a time (default: 2 ** 14)
106
- -r ROWS, --first-row ROWS
107
- the first row to process (zero based)
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 DATE, --server-date DATE
112
+ -D, --server-date DATE
118
113
  OFX server date (default: source file mtime)
119
- -E ENCODING, --encoding ENCODING
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
- If you would like to import csv files with field names different from the default, you can modify the mapping file or create your own. New mappings must be placed in the `csv2ofx/mappings` folder (otherwise you must use the ). The mapping object consists of a dictionary whose keys are OFX/QIF attributes and whose values are functions which should return the corresponding value from a record (csv row). The mapping function will take in a record, e.g.,
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,46 @@ 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
- csv2ofx comes with a built in task manager `manage.py`.
233
+ ### Running tests
239
234
 
240
- ### Setup
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. If you add new classes or functions, please add the appropriate doc blocks with examples. Also, make sure the python linter and nose tests pass.
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 git@github.com:<your_username>/csv2ofx.git
246
+ git clone https://github.com/reubano/csv2ofx
263
247
  cd csv2ofx
264
248
  ```
265
249
 
266
- 2. Setup a new [virtualenv](http://www.virtualenv.org/en/latest/index.html)
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`:
267
253
 
268
254
  ```bash
269
- mkvirtualenv -i pkutils csv2ofx
270
- activate csv2ofx
271
- python setup.py develop
272
- pip install -r dev-requirements.txt
255
+ tox
273
256
  ```
274
257
 
258
+ Tox will run the tests and other checks (linter) in different Python environments. It will create a Python environment in `.tox/py` and install csv2ofx there.
259
+
260
+ Feel free to activate that environment or create a separate one.
261
+
275
262
  3. Create a branch for local development
276
263
 
277
264
  ```bash
278
265
  git checkout -b name-of-your-bugfix-or-feature
279
266
  ```
280
267
 
281
- 4. Make your changes, run linter and tests (see above), and submit a pull request through the GitHub website.
268
+ 4. Make your changes, run tests (see above), and submit a pull request through the GitHub website.
282
269
 
283
270
  ### Adding Mappings
284
271
 
@@ -287,8 +274,8 @@ How to contribute a mapping:
287
274
  1. Add the mapping in `csv2ofx/mappings/`
288
275
  2. Add a simple example CSV file in `data/test/`.
289
276
  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`. If you added 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 on your workstation and fail on the build server.
291
- 5. Ensure your test succeeds (see above).
277
+ 4. Add a `csv2ofx` call for your mapping to the tests in `tests/test_cli.py`, in `samples`. 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.
278
+ 5. Ensure the test succeeds (see above).
292
279
 
293
280
  ## License
294
281
 
@@ -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,19 @@ 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
27
23
 
28
- from builtins import *
29
- from six.moves import filterfalse
30
- from meza.process import merge, group
31
24
  from dateutil.parser import parse
25
+ from meza.process import group, merge
32
26
 
33
27
  from . import utils
34
28
 
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
29
 
45
30
  # pylint: disable=invalid-name
46
- md5 = lambda content: hashlib.md5(content.encode("utf-8")).hexdigest()
31
+ def md5(content):
32
+ return hashlib.md5(content.encode("utf-8")).hexdigest()
47
33
 
48
34
 
49
35
  class BalanceError(Exception):
@@ -52,7 +38,7 @@ class BalanceError(Exception):
52
38
  pass
53
39
 
54
40
 
55
- class Content(object): # pylint: disable=too-many-instance-attributes
41
+ class Content: # pylint: disable=too-many-instance-attributes
56
42
  """A transaction holding object"""
57
43
 
58
44
  def __init__(self, mapping=None, **kwargs):
@@ -81,7 +67,7 @@ class Content(object): # pylint: disable=too-many-instance-attributes
81
67
  self.account = "N/A"
82
68
  self.parse_fmt = kwargs.get("parse_fmt")
83
69
  self.dayfirst = kwargs.get("dayfirst")
84
- self.filter = kwargs.get("filter")
70
+ self.filter = kwargs.get("filter") or bool
85
71
  self.ms_money = kwargs.get("ms_money")
86
72
  self.split_account = None
87
73
  self.inv_split_account = None
@@ -156,9 +142,10 @@ class Content(object): # pylint: disable=too-many-instance-attributes
156
142
 
157
143
  return value
158
144
 
159
- def skip_transaction(self, trxn):
160
- """Determines whether a transaction should be skipped (isn't in the
161
- specified date range, etc.)
145
+ def include(self, trxn):
146
+ """Determines whether a transaction should be included.
147
+
148
+ Included if within the specified date range and any custom filter.
162
149
 
163
150
  Args:
164
151
  trxn (dict): The transaction.
@@ -171,13 +158,21 @@ class Content(object): # pylint: disable=too-many-instance-attributes
171
158
  >>> from datetime import datetime as dt
172
159
  >>>
173
160
  >>> trxn = {'Date': '06/12/10', 'Amount': 1000.00}
174
- >>> Content(mapping, start=dt(2010, 1, 1)).skip_transaction(trxn)
175
- False
176
- >>> Content(mapping, start=dt(2013, 1, 1)).skip_transaction(trxn)
161
+ >>> Content(mapping, start=dt(2010, 1, 1)).include(trxn)
177
162
  True
163
+ >>> Content(mapping, start=dt(2013, 1, 1)).include(trxn)
164
+ False
178
165
  """
179
- keep = self.end >= self.parse_date(trxn) >= self.start
180
- return not (self.filter(trxn) if keep and self.filter else keep)
166
+ return all(
167
+ filter_(trxn)
168
+ for filter_ in (
169
+ self.filter,
170
+ self.in_range,
171
+ )
172
+ )
173
+
174
+ def in_range(self, trxn):
175
+ return self.start <= self.parse_date(trxn) <= self.end
181
176
 
182
177
  def convert_amount(self, trxn):
183
178
  """Converts a string amount into a number
@@ -250,7 +245,7 @@ class Content(object): # pylint: disable=too-many-instance-attributes
250
245
  payee = self.get("payee", trxn)
251
246
  desc = self.get("desc", trxn)
252
247
  notes = self.get("notes", trxn)
253
- memo = "%s %s" % (desc, notes) if desc and notes else desc or notes
248
+ memo = f"{desc} {notes}" if desc and notes else desc or notes
254
249
  check_num = self.get("check_num", trxn)
255
250
  details = "".join(filter(None, [date, raw_amount, payee, memo]))
256
251
  category = self.get("category", trxn, "")
@@ -307,7 +302,10 @@ class Content(object): # pylint: disable=too-many-instance-attributes
307
302
  if self.is_split and collapse:
308
303
  # group transactions by `collapse` field and sum the amounts
309
304
  byaccount = group(transactions, collapse)
310
- oprtn = lambda values: sum(map(utils.convert_amount, values))
305
+
306
+ def oprtn(values):
307
+ return sum(map(utils.convert_amount, values))
308
+
311
309
  merger = partial(merge, pred=self.amount, op=oprtn)
312
310
  trxns = [merger(dicts) for _, dicts in byaccount]
313
311
  else:
@@ -320,13 +318,13 @@ class Content(object): # pylint: disable=too-many-instance-attributes
320
318
  for grp, trxns in groups:
321
319
  _args = [trxns, self.convert_amount]
322
320
 
323
- # if it's split, transaction skipping is all or none
324
- if self.is_split and self.skip_transaction(trxns[0]):
321
+ # if it's split, transaction inclusion is all or none
322
+ if self.is_split and not self.include(trxns[0]):
325
323
  continue
326
324
  elif self.is_split and not utils.verify_splits(*_args):
327
325
  raise Exception("Splits do not sum to zero.")
328
326
  elif not self.is_split:
329
- filtered_trxns = filterfalse(self.skip_transaction, trxns)
327
+ filtered_trxns = filter(self.include, trxns)
330
328
  else:
331
329
  filtered_trxns = trxns
332
330
 
@@ -336,6 +334,8 @@ class Content(object): # pylint: disable=too-many-instance-attributes
336
334
  main_pos = 0
337
335
 
338
336
  # pylint: disable=cell-var-from-loop
339
- keyfunc = lambda enum: enum[0] != main_pos
337
+ def keyfunc(enum):
338
+ return enum[0] != main_pos
339
+
340
340
  sorted_trxns = sorted(enumerate(filtered_trxns), key=keyfunc)
341
341
  yield (grp, main_pos, sorted_trxns)
@@ -0,0 +1,3 @@
1
+ from . import main
2
+
3
+ __name__ == "__main__" and main.run()
@@ -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 sys import stdin, stdout, exit
22
+ from argparse import ArgumentParser, RawTextHelpFormatter
23
+ from datetime import datetime as dt
25
24
  from importlib import import_module, util
26
- from pkgutil import iter_modules
25
+ from math import inf
27
26
  from operator import itemgetter
28
27
  from os import path as p
29
- from io import open
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 math import inf
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
- from builtins import *
37
+ import builtins
38
+
41
39
  from dateutil.parser import parse
42
- from meza.io import read_csv, IterStringIO, write
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%s" % version)
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.%s" % args.mapping)
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 = open(args.source, encoding=args.encoding) if args.source else stdin
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 = open(args.dest, "w", encoding=args.encoding) if args.dest else stdout
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 %s is missing from file. Check `mapping` option." % err
285
+ msg = f"Field {err} is missing from file. Check `mapping` option."
285
286
  except TypeError as err:
286
- msg = "No data to write. %s. " % str(err)
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: %s. " % str(err)
295
+ msg = f"Possible mapping problem: {str(err)}."
295
296
  parser.print_help()
296
297
  except BalanceError as err:
297
- msg = "%s. Try again with `--ending-balance` option." % err
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()