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.
Files changed (128) hide show
  1. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/MANIFEST.in +1 -1
  2. {csv2ofx-0.32.0/csv2ofx.egg-info → csv2ofx-0.33.0}/PKG-INFO +49 -52
  3. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/README.md +42 -51
  4. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/__init__.py +14 -22
  5. csv2ofx-0.33.0/csv2ofx/__main__.py +3 -0
  6. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/main.py +21 -20
  7. csv2ofx-0.33.0/csv2ofx/mappings/__init__.py +6 -0
  8. csv2ofx-0.33.0/csv2ofx/mappings/abnamro.py +12 -0
  9. csv2ofx-0.33.0/csv2ofx/mappings/amazon.py +60 -0
  10. csv2ofx-0.33.0/csv2ofx/mappings/boursorama.py +17 -0
  11. csv2ofx-0.33.0/csv2ofx/mappings/capitalone.py +15 -0
  12. csv2ofx-0.33.0/csv2ofx/mappings/creditunion.py +14 -0
  13. csv2ofx-0.33.0/csv2ofx/mappings/custom.py +21 -0
  14. csv2ofx-0.33.0/csv2ofx/mappings/default.py +17 -0
  15. csv2ofx-0.33.0/csv2ofx/mappings/eqbank.py +14 -0
  16. csv2ofx-0.33.0/csv2ofx/mappings/exim.py +13 -0
  17. csv2ofx-0.33.0/csv2ofx/mappings/gls.py +23 -0
  18. csv2ofx-0.33.0/csv2ofx/mappings/ingdirect.py +20 -0
  19. csv2ofx-0.33.0/csv2ofx/mappings/ingesp.py +85 -0
  20. csv2ofx-0.33.0/csv2ofx/mappings/mdb.py +22 -0
  21. csv2ofx-0.33.0/csv2ofx/mappings/mint.py +23 -0
  22. csv2ofx-0.33.0/csv2ofx/mappings/mint_extra.py +28 -0
  23. csv2ofx-0.33.0/csv2ofx/mappings/mint_headerless.py +22 -0
  24. csv2ofx-0.33.0/csv2ofx/mappings/mintapi.py +30 -0
  25. csv2ofx-0.33.0/csv2ofx/mappings/msmoneyreport.py +16 -0
  26. csv2ofx-0.33.0/csv2ofx/mappings/n26.py +34 -0
  27. csv2ofx-0.33.0/csv2ofx/mappings/outbank.py +23 -0
  28. csv2ofx-0.33.0/csv2ofx/mappings/payoneer.py +52 -0
  29. csv2ofx-0.33.0/csv2ofx/mappings/pcmastercard.py +16 -0
  30. csv2ofx-0.33.0/csv2ofx/mappings/rabobank.py +29 -0
  31. csv2ofx-0.33.0/csv2ofx/mappings/schwabchecking.py +19 -0
  32. csv2ofx-0.33.0/csv2ofx/mappings/split_account.py +18 -0
  33. csv2ofx-0.33.0/csv2ofx/mappings/starling.py +16 -0
  34. csv2ofx-0.33.0/csv2ofx/mappings/stripe.py +31 -0
  35. csv2ofx-0.33.0/csv2ofx/mappings/ubs-ch-fr.py +77 -0
  36. csv2ofx-0.33.0/csv2ofx/mappings/ubs.py +16 -0
  37. csv2ofx-0.33.0/csv2ofx/mappings/xero.py +14 -0
  38. csv2ofx-0.33.0/csv2ofx/mappings/yodlee.py +23 -0
  39. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/ofx.py +58 -65
  40. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/qif.py +26 -28
  41. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx/utils.py +22 -22
  42. {csv2ofx-0.32.0 → csv2ofx-0.33.0/csv2ofx.egg-info}/PKG-INFO +49 -52
  43. csv2ofx-0.33.0/csv2ofx.egg-info/SOURCES.txt +123 -0
  44. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/requires.txt +6 -0
  45. csv2ofx-0.33.0/data/converted/amazon.ofx +51 -0
  46. csv2ofx-0.33.0/data/converted/creditunion.qif +45 -0
  47. csv2ofx-0.33.0/data/converted/default.ofx +111 -0
  48. csv2ofx-0.33.0/data/converted/default.qif +50 -0
  49. csv2ofx-0.33.0/data/converted/default_w_splits.ofx +167 -0
  50. csv2ofx-0.33.0/data/converted/default_w_splits.qif +66 -0
  51. csv2ofx-0.33.0/data/converted/gls.ofx +43 -0
  52. csv2ofx-0.33.0/data/converted/ingesp.ofx +115 -0
  53. csv2ofx-0.33.0/data/converted/mint.ofx +95 -0
  54. csv2ofx-0.33.0/data/converted/mint.qif +42 -0
  55. csv2ofx-0.33.0/data/converted/mint_alt.qif +21 -0
  56. csv2ofx-0.33.0/data/converted/mint_extra.qif +34 -0
  57. csv2ofx-0.33.0/data/converted/outbank.ofx +67 -0
  58. csv2ofx-0.33.0/data/converted/payoneer.ofx +55 -0
  59. csv2ofx-0.33.0/data/converted/pcmastercard.ofx +47 -0
  60. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case1.ofx +75 -0
  61. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case2.ofx +71 -0
  62. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case3.ofx +75 -0
  63. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case4.ofx +75 -0
  64. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case5.ofx +75 -0
  65. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case6.ofx +75 -0
  66. csv2ofx-0.33.0/data/converted/schwab-checking-baltest-case7.ofx +53 -0
  67. csv2ofx-0.33.0/data/converted/schwab-checking-msmoney.ofx +79 -0
  68. csv2ofx-0.33.0/data/converted/schwab-checking.ofx +75 -0
  69. csv2ofx-0.33.0/data/converted/stripe-all.ofx +75 -0
  70. csv2ofx-0.33.0/data/converted/stripe-all.qif +30 -0
  71. csv2ofx-0.33.0/data/converted/stripe-default.ofx +75 -0
  72. csv2ofx-0.33.0/data/converted/stripe-default.qif +26 -0
  73. csv2ofx-0.33.0/data/converted/ubs-ch-fr.qif +25 -0
  74. csv2ofx-0.33.0/data/converted/xero.qif +64 -0
  75. csv2ofx-0.33.0/data/example/investment_example.qif +24 -0
  76. csv2ofx-0.33.0/data/example/transaction_example.ofx +46 -0
  77. csv2ofx-0.33.0/data/example/transfer_example.ofx +41 -0
  78. csv2ofx-0.33.0/data/test/amazon.csv +5 -0
  79. csv2ofx-0.33.0/data/test/capitalone.csv +3 -0
  80. csv2ofx-0.33.0/data/test/creditunion.csv +1 -0
  81. csv2ofx-0.33.0/data/test/default.csv +9 -0
  82. csv2ofx-0.33.0/data/test/gls.csv +2 -0
  83. csv2ofx-0.33.0/data/test/ingesp.csv +11 -0
  84. csv2ofx-0.33.0/data/test/mint.csv +1 -0
  85. csv2ofx-0.33.0/data/test/mint_extra.csv +1 -0
  86. csv2ofx-0.33.0/data/test/mint_headerless.csv +1 -0
  87. csv2ofx-0.33.0/data/test/outbank.csv +5 -0
  88. csv2ofx-0.33.0/data/test/payoneer.csv +3 -0
  89. csv2ofx-0.33.0/data/test/pcmastercard.csv +3 -0
  90. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case1.csv +5 -0
  91. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case2.csv +5 -0
  92. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case3.csv +5 -0
  93. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case4.csv +5 -0
  94. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case5.csv +5 -0
  95. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case6.csv +5 -0
  96. csv2ofx-0.33.0/data/test/schwab-checking-baltest-case7.csv +3 -0
  97. csv2ofx-0.33.0/data/test/schwab-checking.csv +5 -0
  98. csv2ofx-0.33.0/data/test/stripe-all.csv +6 -0
  99. csv2ofx-0.33.0/data/test/stripe-default.csv +6 -0
  100. csv2ofx-0.33.0/data/test/ubs-ch-fr_trimmed.csv +4 -0
  101. csv2ofx-0.33.0/data/test/xero.csv +1 -0
  102. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/pyproject.toml +16 -6
  103. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/tests/test.py +32 -30
  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 → csv2ofx-0.33.0}/LICENSE +0 -0
  108. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/dependency_links.txt +0 -0
  109. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/entry_points.txt +0 -0
  110. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/csv2ofx.egg-info/top_level.txt +0 -0
  111. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFX 2.1.1.pdf +0 -0
  112. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFXAudit.xls +0 -0
  113. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/OFX_Message_Support.doc +0 -0
  114. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification.html +0 -0
  115. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a.html +0 -0
  116. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_002.html +0 -0
  117. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_003.html +0 -0
  118. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_004.html +0 -0
  119. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/a_005.html +0 -0
  120. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/bootstrap.js +0 -0
  121. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/jquery.js +0 -0
  122. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/QIF Specification_files/sitecss.css +0 -0
  123. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/docs/qif-file-format.txt +0 -0
  124. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/check-stage +0 -0
  125. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/clean +0 -0
  126. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/srcdist +0 -0
  127. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/helpers/wheel +0 -0
  128. {csv2ofx-0.32.0 → csv2ofx-0.33.0}/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
1
  Metadata-Version: 2.2
2
2
  Name: csv2ofx
3
- Version: 0.32.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
- [![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,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
- 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`:
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
- mkvirtualenv -i pkutils csv2ofx
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 linter and tests (see above), and submit a pull request through the GitHub website.
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`. 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.
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
- [![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,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
- 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`:
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
- mkvirtualenv -i pkutils csv2ofx
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 linter and tests (see above), and submit a pull request through the GitHub website.
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`. 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.
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
- md5 = lambda content: hashlib.md5(content.encode("utf-8")).hexdigest()
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(object): # pylint: disable=too-many-instance-attributes
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 = "%s %s" % (desc, notes) if desc and notes else desc or notes
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
- oprtn = lambda values: sum(map(utils.convert_amount, values))
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 = lambda enum: enum[0] != main_pos
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)
@@ -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()
@@ -0,0 +1,6 @@
1
+ """
2
+ csv2ofx.mappings
3
+ ~~~~~~~~~~~~~~~~
4
+
5
+ Bank Mappers
6
+ """
@@ -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
+ }