├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── .gitignore ├── CHANGES.rst ├── LICENSE.txt ├── MANIFEST.in ├── Makefile ├── Pipfile ├── Pipfile.lock ├── README.rst ├── doc └── ofx_sample_files │ ├── ofx_spec201_invest_transactions_example.xml │ └── ofx_spec201_stmtrs_example.xml ├── pyproject.toml ├── pytest.ini ├── setup.cfg ├── setup.py └── src └── ofxstatement ├── __init__.py ├── configuration.py ├── exceptions.py ├── ofx.py ├── parser.py ├── plugin.py ├── plugins ├── README.txt └── __init__.py ├── py.typed ├── statement.py ├── tests ├── __init__.py ├── samples │ └── config.ini ├── test_configuration.py ├── test_ofx.py ├── test_ofx_invest.py ├── test_parser.py ├── test_plugin.py ├── test_statement.py └── test_tool.py ├── tool.py └── ui.py /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | day: "saturday" 8 | time: "03:00" 9 | open-pull-requests-limit: 10 10 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: ofxstatement 2 | 3 | on: 4 | push: 5 | branches: master 6 | pull_request: 7 | 8 | jobs: 9 | test: 10 | 11 | runs-on: ubuntu-latest 12 | strategy: 13 | matrix: 14 | python-version: ["3.9", "3.10", "3.11", "3.12"] 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install pipenv coveralls 26 | pipenv sync --dev 27 | - name: Test with pytest 28 | run: | 29 | pipenv run pytest -v --cov src/ofxstatement 30 | 31 | - name: Check with mypy 32 | run: | 33 | pipenv run mypy src 34 | - name: Check with black 35 | run: | 36 | pipenv run black --check setup.py src 37 | - name: Coveralls 38 | if: ${{ success() }} 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN}} 42 | COVERALLS_PARALLEL: true 43 | run: | 44 | coveralls --service=github 45 | 46 | report: 47 | needs: test 48 | runs-on: ubuntu-latest 49 | steps: 50 | - name: Set up Python 51 | uses: actions/setup-python@v2 52 | - name: Coveralls Finish 53 | env: 54 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN}} 56 | run: | 57 | pip install coveralls 58 | coveralls --service=github --finish 59 | 60 | integration-test: 61 | needs: test 62 | runs-on: ubuntu-latest 63 | strategy: 64 | matrix: 65 | python-version: ["3.9", "3.10", "3.11", "3.12"] 66 | 67 | steps: 68 | - uses: actions/checkout@v2 69 | - name: Set up Python ${{ matrix.python-version }} 70 | uses: actions/setup-python@v2 71 | with: 72 | python-version: ${{ matrix.python-version }} 73 | - name: Build and install wheel 74 | run: | 75 | python -m pip install --upgrade pip 76 | pip install build wheel 77 | python -m build 78 | pip install dist/*.whl 79 | - name: Check some plugins 80 | run: | 81 | pip install ofxstatement-lithuanian 82 | ofxstatement list-plugins | grep swedbank 83 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | .installed.cfg 4 | develop-eggs 5 | dist 6 | src/ofxstatement.egg-info 7 | bin 8 | parts 9 | tags 10 | misc 11 | build 12 | eggs 13 | *.egg 14 | .coverage 15 | .venv 16 | .project 17 | .pydevproject 18 | *.sublime* 19 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changes 2 | ------- 3 | 4 | 0.9.4 (unreleased) 5 | ================== 6 | 7 | - Nothing changed yet. 8 | 9 | 10 | 0.9.3 (2025-09-10) 11 | ================== 12 | 13 | - Better ofx spec compliance (#332) 14 | - Add support for INVEXPENSE (#346) 15 | - Conversion report now reports invest-lines too (#352) 16 | 17 | 18 | 0.9.2 (2024-11-25) 19 | ================== 20 | 21 | - Get rid of build deprecation warnings (#322) 22 | 23 | - Replace deprecated appdirs with platformdirs (#323) 24 | 25 | - Switch to importlib.metadata from deprecated pkg_resources for plugin lookup (internal 26 | infrastructure update, #262) 27 | - Fix invest transactions unit precision (#257) 28 | 29 | 30 | 0.9.1 (2023-09-16) 31 | ================== 32 | 33 | - Make OFX output conform to DTD (#243). 34 | 35 | 36 | 0.9.0 (2023-08-07) 37 | ================== 38 | 39 | - New `-c` (`--config`) option for `convert` command, allows to specify the 40 | configuration file to use (#235). 41 | - Print the number of transactions in the output (#236). 42 | 43 | 44 | 0.8.0 (2021-09-06) 45 | ================== 46 | 47 | - Support OFX CURRENCY and ORIGCURRENCY in statement lines. This allows plugins 48 | to add information about transaction currency to generated OFX statements. 49 | - Add `--pretty` flag to `convert` command to produce nicely intented OFX files. 50 | 51 | 0.7.1 (2020-09-14) 52 | ================== 53 | 54 | - Include PEP-561 marker into source code distribution 55 | 56 | 57 | 0.7.0 (2020-09-13) 58 | ================== 59 | 60 | - Drop support for Python 3.4, 3.5, add support for Python 3.8 61 | - Fixed naive end balance validation (#106) 62 | - Modernize development environment (use pipenv, mypy, black) 63 | 64 | 0.6.5 (2020-06-09) 65 | ================== 66 | 67 | - Added balance checks and improved generation of unique ids (#100, #104) 68 | 69 | 70 | 0.6.4 (2020-03-04) 71 | ================== 72 | 73 | - Fix regression introduced in 0.6.3 - `edit-config` command stopped working. 74 | 75 | 76 | 0.6.3 (2020-02-13) 77 | ================== 78 | 79 | - Fix config editing on Windows 80 | 81 | 0.6.2 (2020-01-20) 82 | ================== 83 | 84 | - Better `EDITOR` environment variable handling for `edit-config` command 85 | - Support Python-3.7 86 | - API: type of StatementLine.date_user (date when user initiated transaction) 87 | will not be a string by default. 88 | - API: More unique generated transaction ids (when one is not available from 89 | the statement file) 90 | 91 | 0.6.1 (2017-05-07) 92 | ================== 93 | 94 | - Fix installation problem on python-3.5 (#55) 95 | 96 | 97 | 0.6.0 (2016-12-02) 98 | ================== 99 | 100 | - Support for specifying account information for each parsed satatement 101 | line and translate it to BANKACCTTO aggregate in OFX. 102 | 103 | - Command line option to display debugging information (--debug). 104 | 105 | - Fix config file location for appdirs >= 1.3.0 106 | 107 | 0.5.0 (2013-11-03) 108 | ================== 109 | 110 | - Plugins are now registered via setuptools' entry-points mechanism. This 111 | allows plugins to live in separate eggs and developed independently of 112 | ofxstatement itself. Plugins are registered as 'ofxstatement' entry points 113 | (#11). 114 | 115 | 116 | - Command line interface changed: ``ofxstatement`` now accepts "action" 117 | parameter and few actions were added: 118 | 119 | * ``ofxstatement convert``: perform conversion to OFX 120 | * ``ofxstatement list-plugins``: list available conversion plugins 121 | * ``ofxstatement edit-config``: launch default editor to edit configuration 122 | file 123 | 124 | - ``ofxstatement convert`` can be run without any configuration. Plugin name 125 | to use is specified using ``-t TYPE`` parameter in this case (#12). 126 | 127 | - ``StatementLine`` supports more attributes, translated to OFX (#13): 128 | 129 | * ``refnum`` - translated to ```` in OFX. 130 | * ``trntype`` - translated to ```` in OFX. 131 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CHANGES.rst README.rst LICENSE.txt 2 | include src/ofxstatement/plugins/README.txt 3 | include src/ofxstatement/py.typed 4 | include Pipfile Pipfile.lock 5 | include Makefile 6 | include pytest.ini 7 | graft src/ofxstatement/tests/samples 8 | recursive-include doc *.xml 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: test mypy black 2 | 3 | PHONY: test 4 | test: 5 | pytest 6 | 7 | PHONY: coverage 8 | coverage: bin/pytest 9 | pytest --cov src/ofxstatement 10 | 11 | .PHONY: black 12 | black: 13 | black setup.py src 14 | 15 | .PHONY: mypy 16 | mypy: 17 | mypy src 18 | 19 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | name = "pypi" 3 | url = "https://pypi.org/simple" 4 | verify_ssl = true 5 | 6 | [dev-packages] 7 | pytest = "*" 8 | pytest-cov = "*" 9 | black = "*" 10 | mypy = "*" 11 | exceptiongroup = {markers="python_version < '3.11'"} 12 | tomli = {markers="python_version < '3.11'"} 13 | 14 | [packages] 15 | ofxstatement = {editable = true,path = "."} 16 | exceptiongroup = "*" 17 | importlib_metadata = { markers="python_version < '3.10'"} 18 | zipp = { markers="python_version < '3.10'"} 19 | platformdirs = "*" 20 | -------------------------------------------------------------------------------- /Pipfile.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "cb8ca6d3c3b7984a4c9e4213648559c64f0f7816a82f0b6d45646fbdc6fff283" 5 | }, 6 | "pipfile-spec": 6, 7 | "requires": {}, 8 | "sources": [ 9 | { 10 | "name": "pypi", 11 | "url": "https://pypi.org/simple", 12 | "verify_ssl": true 13 | } 14 | ] 15 | }, 16 | "default": { 17 | "exceptiongroup": { 18 | "hashes": [ 19 | "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b", 20 | "sha256:47c2edf7c6738fafb49fd34290706d1a1a2f4d1c6df275526b62cbb4aa5393cc" 21 | ], 22 | "index": "pypi", 23 | "markers": "python_version >= '3.7'", 24 | "version": "==1.2.2" 25 | }, 26 | "importlib-metadata": { 27 | "markers": "python_version < '3.10'", 28 | "version": "==3.8" 29 | }, 30 | "ofxstatement": { 31 | "editable": true, 32 | "path": "." 33 | }, 34 | "platformdirs": { 35 | "hashes": [ 36 | "sha256:357fb2acbc885b0419afd3ce3ed34564c13c9b95c89360cd9563f73aa5e2b907", 37 | "sha256:73e575e1408ab8103900836b97580d5307456908a03e92031bab39e4554cc3fb" 38 | ], 39 | "index": "pypi", 40 | "markers": "python_version >= '3.8'", 41 | "version": "==4.3.6" 42 | }, 43 | "zipp": { 44 | "hashes": [ 45 | "sha256:2c9958f6430a2040341a52eb608ed6dd93ef4392e02ffe219417c1b28b5dd1f4", 46 | "sha256:ac1bbe05fd2991f160ebce24ffbac5f6d11d83dc90891255885223d42b3cd931" 47 | ], 48 | "index": "pypi", 49 | "markers": "python_version >= '3.9'", 50 | "version": "==3.21.0" 51 | } 52 | }, 53 | "develop": { 54 | "black": { 55 | "hashes": [ 56 | "sha256:0172a012f725b792c358d57fe7b6b6e8e67375dd157f64fa7a3097b3ed3e2175", 57 | "sha256:0474bca9a0dd1b51791fcc507a4e02078a1c63f6d4e4ae5544b9848c7adfb619", 58 | "sha256:154b06d618233fe468236ba1f0e40823d4eb08b26f5e9261526fde34916b9140", 59 | "sha256:1b9dc70c21ef8b43248f1d86aedd2aaf75ae110b958a7909ad8463c4aa0880b0", 60 | "sha256:2ab0ce111ef026790e9b13bd216fa7bc48edd934ffc4cbf78808b235793cbc92", 61 | "sha256:3bec74ee60f8dfef564b573a96b8930f7b6a538e846123d5ad77ba14a8d7a64f", 62 | "sha256:456386fe87bad41b806d53c062e2974615825c7a52159cde7ccaeb0695fa28fa", 63 | "sha256:474b34c1342cdc157d307b56c4c65bce916480c4a8f6551fdc6bf9b486a7c4ae", 64 | "sha256:77e7060a00c5ec4b3367c55f39cf9b06e68965a4f2e61cecacd6d0d9b7ec945a", 65 | "sha256:846d58e3ce7879ec1ffe816bb9df6d006cd9590515ed5d17db14e17666b2b357", 66 | "sha256:8e46eecf65a095fa62e53245ae2795c90bdecabd53b50c448d0a8bcd0d2e74c4", 67 | "sha256:9101ee58ddc2442199a25cb648d46ba22cd580b00ca4b44234a324e3ec7a0f7e", 68 | "sha256:a16b14a44c1af60a210d8da28e108e13e75a284bf21a9afa6b4571f96ab8bb9d", 69 | "sha256:aaf319612536d502fdd0e88ce52d8f1352b2c0a955cc2798f79eeca9d3af0608", 70 | "sha256:b756fc75871cb1bcac5499552d771822fd9db5a2bb8db2a7247936ca48f39831", 71 | "sha256:c0372a93e16b3954208417bfe448e09b0de5cc721d521866cd9e0acac3c04a1f", 72 | "sha256:ce41ed2614b706fd55fd0b4a6909d06b5bab344ffbfadc6ef34ae50adba3d4f7", 73 | "sha256:d119957b37cc641596063cd7db2656c5be3752ac17877017b2ffcdb9dfc4d2b1", 74 | "sha256:e3c1f4cd5e93842774d9ee4ef6cd8d17790e65f44f7cdbaab5f2cf8ccf22a823", 75 | "sha256:e593466de7b998374ea2585a471ba90553283fb9beefcfa430d84a2651ed5933", 76 | "sha256:ef69351df3c84485a8beb6f7b8f9721e2009e20ef80a8d619e2d1788b7816d47", 77 | "sha256:f96b6726d690c96c60ba682955199f8c39abc1ae0c3a494a9c62c0184049a713" 78 | ], 79 | "index": "pypi", 80 | "markers": "python_version >= '3.9'", 81 | "version": "==25.9.0" 82 | }, 83 | "click": { 84 | "hashes": [ 85 | "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2", 86 | "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a" 87 | ], 88 | "markers": "python_version >= '3.7'", 89 | "version": "==8.1.8" 90 | }, 91 | "coverage": { 92 | "extras": [ 93 | "toml" 94 | ], 95 | "hashes": [ 96 | "sha256:0a07757de9feb1dfafd16ab651e0f628fd7ce551604d1bf23e47e1ddca93f08a", 97 | "sha256:0a17eaf46f56ae0f870f14a3cbc2e4632fe3771eab7f687eda1ee59b73d09fe4", 98 | "sha256:0b4a4cb73b9f2b891c1788711408ef9707666501ba23684387277ededab1097c", 99 | "sha256:0c0378ba787681ab1897f7c89b415bd56b0b2d9a47e5a3d8dc0ea55aac118d6c", 100 | "sha256:115db3d1f4d3f35f5bb021e270edd85011934ff97c8797216b62f461dd69374b", 101 | "sha256:123d589f32c11d9be7fe2e66d823a236fe759b0096f5db3fb1b75b2fa414a4fa", 102 | "sha256:14fa8d3da147f5fdf9d298cacc18791818f3f1a9f542c8958b80c228320e90c6", 103 | "sha256:19e7be4cfec248df38ce40968c95d3952fbffd57b400d4b9bb580f28179556d2", 104 | "sha256:1df6b76e737c6a92210eebcb2390af59a141f9e9430210595251fbaf02d46926", 105 | "sha256:1e2f097eae0e5991e7623958a24ced3282676c93c013dde41399ff63e230fcf2", 106 | "sha256:256ea87cb2a1ed992bcdfc349d8042dcea1b80436f4ddf6e246d6bee4b5d73b6", 107 | "sha256:28dc1f67e83a14e7079b6cea4d314bc8b24d1aed42d3582ff89c0295f09b181e", 108 | "sha256:2c8937fa16c8c9fbbd9f118588756e7bcdc7e16a470766a9aef912dd3f117dbd", 109 | "sha256:2d0d4f6ecdf37fcc19c88fec3e2277d5dee740fb51ffdd69b9579b8c31e4232e", 110 | "sha256:2f3da12e0ccbcb348969221d29441ac714bbddc4d74e13923d3d5a7a0bebef7a", 111 | "sha256:31991156251ec202c798501e0a42bbdf2169dcb0f137b1f5c0f4267f3fc68ef9", 112 | "sha256:326802760da234baf9f2f85a39e4a4b5861b94f6c8d95251f699e4f73b1835dc", 113 | "sha256:333b2e0ca576a7dbd66e85ab402e35c03b0b22f525eed82681c4b866e2e2653a", 114 | "sha256:42da2280c4d30c57a9b578bafd1d4494fa6c056d4c419d9689e66d775539be74", 115 | "sha256:48f82f889c80af8b2a7bb6e158d95a3fbec6a3453a1004d04e4f3b5945a02694", 116 | "sha256:49b752a2858b10580969ec6af6f090a9a440a64a301ac1528d7ca5f7ed497f4d", 117 | "sha256:4b1c2d8363247b46bd51f393f86c94096e64a1cf6906803fa8d5a9d03784bdbf", 118 | "sha256:4e01d138540ef34fcf35c1aa24d06c3de2a4cffa349e29a10056544f35cca15f", 119 | "sha256:4e2c058aef613e79df00e86b6d42a641c877211384ce5bd07585ed7ba71ab31b", 120 | "sha256:549cab4892fc82004f9739963163fd3aac7a7b0df430669b75b86d293d2df2a7", 121 | "sha256:55a28954545f9d2f96870b40f6c3386a59ba8ed50caf2d949676dac3ecab99f5", 122 | "sha256:619317bb86de4193debc712b9e59d5cffd91dc1d178627ab2a77b9870deb2868", 123 | "sha256:6406cff19880aaaadc932152242523e892faff224da29e241ce2fca329866584", 124 | "sha256:66283a192a14a3854b2e7f3418d7db05cdf411012ab7ff5db98ff3b181e1f912", 125 | "sha256:669135a9d25df55d1ed56a11bf555f37c922cf08d80799d4f65d77d7d6123fcf", 126 | "sha256:71ae8b53855644a0b1579d4041304ddc9995c7b21c8a1f16753c4d8903b4dfed", 127 | "sha256:82c3939264a76d44fde7f213924021ed31f55ef28111a19649fec90c0f109e6d", 128 | "sha256:82d76ad87c932935417a19b10cfe7abb15fd3f923cfe47dbdaa74ef4e503752d", 129 | "sha256:88d7598b8ee130f32f8a43198ee02edd16d7f77692fa056cb779616bbea1b355", 130 | "sha256:8a1166db2fb62473285bcb092f586e081e92656c7dfa8e9f62b4d39d7e6b5050", 131 | "sha256:9303aed20872d7a3c9cb39c5d2b9bdbe44e3a9a1aecb52920f7e7495410dfab8", 132 | "sha256:985abe7f242e0d7bba228ab01070fde1d6c8fa12f142e43debe9ed1dde686038", 133 | "sha256:997024fa51e3290264ffd7492ec97d0690293ccd2b45a6cd7d82d945a4a80c8b", 134 | "sha256:9ce85551f9a1119f02adc46d3014b5ee3f765deac166acf20dbb851ceb79b6f3", 135 | "sha256:9d3a700304d01a627df9db4322dc082a0ce1e8fc74ac238e2af39ced4c083193", 136 | "sha256:9dfb070f830739ee49d7c83e4941cc767e503e4394fdecb3b54bfdac1d7662c0", 137 | "sha256:a535c0c7364acd55229749c2b3e5eebf141865de3a8f697076a3291985f02d30", 138 | "sha256:a7a56a2964a9687b6aba5b5ced6971af308ef6f79a91043c05dd4ee3ebc3e9ba", 139 | "sha256:ae5d563e970dbe04382f736ec214ef48103d1b875967c89d83c6e3f21706d5b3", 140 | "sha256:ae9eb07f1cfacd9cfe8eaee6f4ff4b8a289a668c39c165cd0c8548484920ffc0", 141 | "sha256:bc18ea9e417a04d1920a9a76fe9ebd2f43ca505b81994598482f938d5c315f46", 142 | "sha256:bcd5ebe66c7a97273d5d2ddd4ad0ed2e706b39630ed4b53e713d360626c3dbb3", 143 | "sha256:bdd612e59baed2a93c8843c9a7cb902260f181370f1d772f4842987535071d14", 144 | "sha256:bf7d773da6af9e10dbddacbf4e5cab13d06d0ed93561d44dae0188a42c65be7e", 145 | "sha256:c10c882b114faf82dbd33e876d0cbd5e1d1ebc0d2a74ceef642c6152f3f4d547", 146 | "sha256:c2667a2b913e307f06aa4e5677f01a9746cd08e4b35e14ebcde6420a9ebb4c62", 147 | "sha256:c33624f50cf8de418ab2b4d6ca9eda96dc45b2c4231336bac91454520e8d1fac", 148 | "sha256:c48c2375287108c887ee87d13b4070a381c6537d30e8487b24ec721bf2a781cb", 149 | "sha256:cdef6504637731a63c133bb2e6f0f0214e2748495ec15fe42d1e219d1b133f0b", 150 | "sha256:d0d67963f9cbfc7c7f96d4ac74ed60ecbebd2ea6eeb51887af0f8dce205e545f", 151 | "sha256:dd7a57b33b5cf27acb491e890720af45db05589a80c1ffc798462a765be6d4d7", 152 | "sha256:ddc39510ac922a5c4c27849b739f875d3e1d9e590d1e7b64c98dadf037a16cce", 153 | "sha256:de3c0378bdf7066c3988d66cd5232d161e933b87103b014ab1b0b4676098fa45", 154 | "sha256:df0f9ef28e0f20c767ccdccfc5ae5f83a6f4a2fbdfbcbcc8487a8a78771168c8", 155 | "sha256:e425cd5b00f6fc0ed7cdbd766c70be8baab4b7839e4d4fe5fac48581dd968ea4", 156 | "sha256:f22627c1fe2745ee98d3ab87679ca73a97e75ca75eb5faee48660d060875465f", 157 | "sha256:f44ae036b63c8ea432f610534a2668b0c3aee810e7037ab9d8ff6883de480f5b", 158 | "sha256:f5fd54310b92741ebe00d9c0d1d7b2b27463952c022da6d47c175d246a98d1bd", 159 | "sha256:f65bb452e579d5540c8b37ec105dd54d8b9307b07bcaa186818c104ffda22441", 160 | "sha256:f8f6389ac977c5fb322e0e38885fbbf901743f79d47f50db706e7644dcdcb6e1", 161 | "sha256:fae939811e14e53ed8a9818dad51d434a41ee09df9305663735f2e2d2d7d959b", 162 | "sha256:ff0d9eae8cdfcd58fe7893b88993723583a6ce4dfbfd9f29e001922544f95615" 163 | ], 164 | "markers": "python_version >= '3.9'", 165 | "version": "==7.9.2" 166 | }, 167 | "exceptiongroup": { 168 | "hashes": [ 169 | "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10", 170 | "sha256:b241f5885f560bc56a59ee63ca4c6a8bfa46ae4ad651af316d4e81817bb9fd88" 171 | ], 172 | "markers": "python_version < '3.11' and python_version < '3.11'", 173 | "version": "==1.3.0" 174 | }, 175 | "iniconfig": { 176 | "hashes": [ 177 | "sha256:3abbd2e30b36733fee78f9c7f7308f2d0050e88f0087fd25c2645f63c773e1c7", 178 | "sha256:9deba5723312380e77435581c6bf4935c94cbfab9b1ed33ef8d238ea168eb760" 179 | ], 180 | "markers": "python_version >= '3.8'", 181 | "version": "==2.1.0" 182 | }, 183 | "mypy": { 184 | "hashes": [ 185 | "sha256:01199871b6110a2ce984bde85acd481232d17413868c9807e95c1b0739a58914", 186 | "sha256:030c52d0ea8144e721e49b1f68391e39553d7451f0c3f8a7565b59e19fcb608b", 187 | "sha256:06a398102a5f203d7477b2923dda3634c36727fa5c237d8f859ef90c42a9924b", 188 | "sha256:07b8b0f580ca6d289e69209ec9d3911b4a26e5abfde32228a288eb79df129fcc", 189 | "sha256:0e2785a84b34a72ba55fb5daf079a1003a34c05b22238da94fcae2bbe46f3544", 190 | "sha256:1331eb7fd110d60c24999893320967594ff84c38ac6d19e0a76c5fd809a84c86", 191 | "sha256:1379451880512ffce14505493bd9fe469e0697543717298242574882cf8cdb8d", 192 | "sha256:20c02215a080e3a2be3aa50506c67242df1c151eaba0dcbc1e4e557922a26075", 193 | "sha256:22a1748707dd62b58d2ae53562ffc4d7f8bcc727e8ac7cbc69c053ddc874d47e", 194 | "sha256:22f27105f1525ec024b5c630c0b9f36d5c1cc4d447d61fe51ff4bd60633f47ac", 195 | "sha256:25a9c8fb67b00599f839cf472713f54249a62efd53a54b565eb61956a7e3296b", 196 | "sha256:33eca32dd124b29400c31d7cf784e795b050ace0e1f91b8dc035672725617e34", 197 | "sha256:3ca30b50a51e7ba93b00422e486cbb124f1c56a535e20eff7b2d6ab72b3b2e37", 198 | "sha256:448acd386266989ef11662ce3c8011fd2a7b632e0ec7d61a98edd8e27472225b", 199 | "sha256:592ec214750bc00741af1f80cbf96b5013d81486b7bb24cb052382c19e40b428", 200 | "sha256:5d6c838e831a062f5f29d11c9057c6009f60cb294fea33a98422688181fe2893", 201 | "sha256:62f0e1e988ad41c2a110edde6c398383a889d95b36b3e60bcf155f5164c4fdce", 202 | "sha256:664dc726e67fa54e14536f6e1224bcfce1d9e5ac02426d2326e2bb4e081d1ce8", 203 | "sha256:6ca1e64b24a700ab5ce10133f7ccd956a04715463d30498e64ea8715236f9c9c", 204 | "sha256:749b5f83198f1ca64345603118a6f01a4e99ad4bf9d103ddc5a3200cc4614adf", 205 | "sha256:776bb00de1778caf4db739c6e83919c1d85a448f71979b6a0edd774ea8399341", 206 | "sha256:7a780ca61fc239e4865968ebc5240bb3bf610ef59ac398de9a7421b54e4a207e", 207 | "sha256:7ab28cc197f1dd77a67e1c6f35cd1f8e8b73ed2217e4fc005f9e6a504e46e7ba", 208 | "sha256:7fb95f97199ea11769ebe3638c29b550b5221e997c63b14ef93d2e971606ebed", 209 | "sha256:807d9315ab9d464125aa9fcf6d84fde6e1dc67da0b6f80e7405506b8ac72bc7f", 210 | "sha256:8795a039bab805ff0c1dfdb8cd3344642c2b99b8e439d057aba30850b8d3423d", 211 | "sha256:a2afc0fa0b0e91b4599ddfe0f91e2c26c2b5a5ab263737e998d6817874c5f7c8", 212 | "sha256:a3c47adf30d65e89b2dcd2fa32f3aeb5e94ca970d2c15fcb25e297871c8e4764", 213 | "sha256:a431a6f1ef14cf8c144c6b14793a23ec4eae3db28277c358136e79d7d062f62d", 214 | "sha256:aa5e07ac1a60a253445797e42b8b2963c9675563a94f11291ab40718b016a7a0", 215 | "sha256:c1eab0cf6294dafe397c261a75f96dc2c31bffe3b944faa24db5def4e2b0f77c", 216 | "sha256:c2b9c7e284ee20e7598d6f42e13ca40b4928e6957ed6813d1ab6348aa3f47133", 217 | "sha256:c3ad2afadd1e9fea5cf99a45a822346971ede8685cc581ed9cd4d42eaf940986", 218 | "sha256:d6985ed057513e344e43a26cc1cd815c7a94602fb6a3130a34798625bc2f07b6", 219 | "sha256:d8068d0afe682c7c4897c0f7ce84ea77f6de953262b12d07038f4d296d547074", 220 | "sha256:d924eef3795cc89fecf6bedc6ed32b33ac13e8321344f6ddbf8ee89f706c05cb", 221 | "sha256:ed4482847168439651d3feee5833ccedbf6657e964572706a2adb1f7fa4dfe2e", 222 | "sha256:f9e171c465ad3901dc652643ee4bffa8e9fef4d7d0eece23b428908c77a76a66" 223 | ], 224 | "index": "pypi", 225 | "markers": "python_version >= '3.9'", 226 | "version": "==1.18.2" 227 | }, 228 | "mypy-extensions": { 229 | "hashes": [ 230 | "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505", 231 | "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558" 232 | ], 233 | "markers": "python_version >= '3.8'", 234 | "version": "==1.1.0" 235 | }, 236 | "packaging": { 237 | "hashes": [ 238 | "sha256:29572ef2b1f17581046b3a2227d5c611fb25ec70ca1ba8554b24b0e69331a484", 239 | "sha256:d443872c98d677bf60f6a1f2f8c1cb748e8fe762d2bf9d3148b5599295b0fc4f" 240 | ], 241 | "markers": "python_version >= '3.8'", 242 | "version": "==25.0" 243 | }, 244 | "pathspec": { 245 | "hashes": [ 246 | "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", 247 | "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712" 248 | ], 249 | "markers": "python_version >= '3.8'", 250 | "version": "==0.12.1" 251 | }, 252 | "platformdirs": { 253 | "hashes": [ 254 | "sha256:abd01743f24e5287cd7a5db3752faf1a2d65353f38ec26d98e25a6db65958c85", 255 | "sha256:ca753cf4d81dc309bc67b0ea38fd15dc97bc30ce419a7f58d13eb3bf14c4febf" 256 | ], 257 | "markers": "python_version >= '3.9'", 258 | "version": "==4.4.0" 259 | }, 260 | "pluggy": { 261 | "hashes": [ 262 | "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", 263 | "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746" 264 | ], 265 | "markers": "python_version >= '3.9'", 266 | "version": "==1.6.0" 267 | }, 268 | "pygments": { 269 | "hashes": [ 270 | "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", 271 | "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b" 272 | ], 273 | "markers": "python_version >= '3.8'", 274 | "version": "==2.19.2" 275 | }, 276 | "pytest": { 277 | "hashes": [ 278 | "sha256:86c0d0b93306b961d58d62a4db4879f27fe25513d4b969df351abdddb3c30e01", 279 | "sha256:872f880de3fc3a5bdc88a11b39c9710c3497a547cfa9320bc3c5e62fbf272e79" 280 | ], 281 | "index": "pypi", 282 | "markers": "python_version >= '3.9'", 283 | "version": "==8.4.2" 284 | }, 285 | "pytest-cov": { 286 | "hashes": [ 287 | "sha256:25cc6cc0a5358204b8108ecedc51a9b57b34cc6b8c967cc2c01a4e00d8a67da2", 288 | "sha256:f5bc4c23f42f1cdd23c70b1dab1bbaef4fc505ba950d53e0081d0730dd7e86d5" 289 | ], 290 | "index": "pypi", 291 | "markers": "python_version >= '3.9'", 292 | "version": "==6.2.1" 293 | }, 294 | "pytokens": { 295 | "hashes": [ 296 | "sha256:c9a4bfa0be1d26aebce03e6884ba454e842f186a59ea43a6d3b25af58223c044", 297 | "sha256:db7b72284e480e69fb085d9f251f66b3d2df8b7166059261258ff35f50fb711b" 298 | ], 299 | "markers": "python_version >= '3.8'", 300 | "version": "==0.1.10" 301 | }, 302 | "tomli": { 303 | "hashes": [ 304 | "sha256:023aa114dd824ade0100497eb2318602af309e5a55595f76b626d6d9f3b7b0a6", 305 | "sha256:02abe224de6ae62c19f090f68da4e27b10af2b93213d36cf44e6e1c5abd19fdd", 306 | "sha256:286f0ca2ffeeb5b9bd4fcc8d6c330534323ec51b2f52da063b11c502da16f30c", 307 | "sha256:2d0f2fdd22b02c6d81637a3c95f8cd77f995846af7414c5c4b8d0545afa1bc4b", 308 | "sha256:33580bccab0338d00994d7f16f4c4ec25b776af3ffaac1ed74e0b3fc95e885a8", 309 | "sha256:400e720fe168c0f8521520190686ef8ef033fb19fc493da09779e592861b78c6", 310 | "sha256:40741994320b232529c802f8bc86da4e1aa9f413db394617b9a256ae0f9a7f77", 311 | "sha256:465af0e0875402f1d226519c9904f37254b3045fc5084697cefb9bdde1ff99ff", 312 | "sha256:4a8f6e44de52d5e6c657c9fe83b562f5f4256d8ebbfe4ff922c495620a7f6cea", 313 | "sha256:4e340144ad7ae1533cb897d406382b4b6fede8890a03738ff1683af800d54192", 314 | "sha256:678e4fa69e4575eb77d103de3df8a895e1591b48e740211bd1067378c69e8249", 315 | "sha256:6972ca9c9cc9f0acaa56a8ca1ff51e7af152a9f87fb64623e31d5c83700080ee", 316 | "sha256:7fc04e92e1d624a4a63c76474610238576942d6b8950a2d7f908a340494e67e4", 317 | "sha256:889f80ef92701b9dbb224e49ec87c645ce5df3fa2cc548664eb8a25e03127a98", 318 | "sha256:8d57ca8095a641b8237d5b079147646153d22552f1c637fd3ba7f4b0b29167a8", 319 | "sha256:8dd28b3e155b80f4d54beb40a441d366adcfe740969820caf156c019fb5c7ec4", 320 | "sha256:9316dc65bed1684c9a98ee68759ceaed29d229e985297003e494aa825ebb0281", 321 | "sha256:a198f10c4d1b1375d7687bc25294306e551bf1abfa4eace6650070a5c1ae2744", 322 | "sha256:a38aa0308e754b0e3c67e344754dff64999ff9b513e691d0e786265c93583c69", 323 | "sha256:a92ef1a44547e894e2a17d24e7557a5e85a9e1d0048b0b5e7541f76c5032cb13", 324 | "sha256:ac065718db92ca818f8d6141b5f66369833d4a80a9d74435a268c52bdfa73140", 325 | "sha256:b82ebccc8c8a36f2094e969560a1b836758481f3dc360ce9a3277c65f374285e", 326 | "sha256:c954d2250168d28797dd4e3ac5cf812a406cd5a92674ee4c8f123c889786aa8e", 327 | "sha256:cb55c73c5f4408779d0cf3eef9f762b9c9f147a77de7b258bef0a5628adc85cc", 328 | "sha256:cd45e1dc79c835ce60f7404ec8119f2eb06d38b1deba146f07ced3bbc44505ff", 329 | "sha256:d3f5614314d758649ab2ab3a62d4f2004c825922f9e370b29416484086b264ec", 330 | "sha256:d920f33822747519673ee656a4b6ac33e382eca9d331c87770faa3eef562aeb2", 331 | "sha256:db2b95f9de79181805df90bedc5a5ab4c165e6ec3fe99f970d0e302f384ad222", 332 | "sha256:e59e304978767a54663af13c07b3d1af22ddee3bb2fb0618ca1593e4f593a106", 333 | "sha256:e85e99945e688e32d5a35c1ff38ed0b3f41f43fad8df0bdf79f72b2ba7bc5272", 334 | "sha256:ece47d672db52ac607a3d9599a9d48dcb2f2f735c6c2d1f34130085bb12b112a", 335 | "sha256:f4039b9cbc3048b2416cc57ab3bda989a6fcf9b36cf8937f01a6e731b64f80d7" 336 | ], 337 | "markers": "python_version < '3.11' and python_version < '3.11'", 338 | "version": "==2.2.1" 339 | }, 340 | "typing-extensions": { 341 | "hashes": [ 342 | "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", 343 | "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548" 344 | ], 345 | "markers": "python_version >= '3.9'", 346 | "version": "==4.15.0" 347 | } 348 | } 349 | } 350 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | OFX Statement 2 | ------------- 3 | 4 | .. image:: https://github.com/kedder/ofxstatement/actions/workflows/test.yml/badge.svg?branch=master 5 | :target: https://github.com/kedder/ofxstatement/actions/workflows/test.yml 6 | .. image:: https://coveralls.io/repos/kedder/ofxstatement/badge.png?branch=master 7 | :target: https://coveralls.io/r/kedder/ofxstatement?branch=master 8 | .. image:: http://www.mypy-lang.org/static/mypy_badge.svg 9 | :target: http://mypy-lang.org/ 10 | .. image:: https://img.shields.io/badge/code%20style-black-000000.svg 11 | :target: https://github.com/psf/black 12 | 13 | Ofxstatement is a tool to convert proprietary bank statements to OFX format, suitable 14 | for importing into personal accounting systems like `GnuCash`_ or `homebank`_. This 15 | package provides a command line tool to run: ``ofxstatement``. Run ``ofxstatement -h`` 16 | for more help. ``ofxstatement`` works under Python 3 and is not compatible with Python 17 | 2. 18 | 19 | .. _GnuCash: https://gnucash.org/ 20 | .. _homebank: https://www.gethomebank.org/ 21 | 22 | 23 | 24 | Rationale 25 | ========= 26 | 27 | Most internet banking systems are capable of exporting account transactions to 28 | some sort of computer readable format, but few support standard data formats, 29 | like `OFX`_. On the other hand, personal accounting systems such as `GnuCash`_ 30 | support standard formats only, and will probably never support proprietary 31 | statement formats of online banking systems. 32 | 33 | To bridge the gap between them, this ofxstatement tool was created. 34 | 35 | .. _GnuCash: https://gnucash.org/ 36 | .. _OFX: https://en.wikipedia.org/wiki/Open_Financial_Exchange 37 | 38 | Mode of Operation 39 | ================= 40 | 41 | The ``ofxstatement`` tool is intended to be used in the following workflow: 42 | 43 | 1. At the end of each month, use your online banking service to export 44 | statements from all of your bank accounts in a format known to 45 | ofxstatement. 46 | 47 | 2. Run ``ofxstatement`` on each exported file to convert it to OFX. 48 | Shell scripts or a Makefile may help to automate this routine. 49 | 50 | 3. Import the generated OFX file into your personal accounting system. 51 | 52 | Installation and Usage 53 | ====================== 54 | 55 | Before using ``ofxstatement``, you have to install a plugin for your bank (or 56 | write your own!). Plugins are installed as regular python packages, with 57 | easy_install or pip, for example:: 58 | 59 | $ pip3 install ofxstatement-lithuanian 60 | 61 | Note that ofxstatement itself will be installed automatically this way. After 62 | the installation, the ``ofxstatement`` utility will be available. 63 | 64 | Users of *Ubuntu* and *Debian* operating systems can install ofxstatement from 65 | official package repositories:: 66 | 67 | $ apt install ofxstatement ofxstatement-plugins 68 | 69 | You can check that ofxstatement is working by running:: 70 | 71 | $ ofxstatement list-plugins 72 | 73 | You should get a list of your installed plugins. 74 | 75 | After installation, the usage is simple:: 76 | 77 | $ ofxstatement convert -t bank_statement.csv statement.ofx 78 | 79 | The resulting ``statement.ofx`` is then ready to be imported into a personal 80 | accounting system. 81 | 82 | Known Plugins 83 | ============= 84 | 85 | There are several user-developed plugins available: 86 | 87 | ================================= ============================================ 88 | Plugin Description 89 | ================================= ============================================ 90 | `ofxstatement-mt940`_ Swift MT940 statements 91 | `ofxstatement-iso20022`_ Generic ISO-20022 format 92 | `ofxstatement-paypal-2`_ PayPal, ``*.csv`` for private accounts 93 | `ofxstatement-transferwise`_ Transferwise CSV (international) 94 | `ofxstatement-nordigen`_ Plugin for GoCardless and Nordigen data parsing 95 | 96 | `ofxstatement-lithuanian`_ Plugins for several banks, operating in 97 | Lithuania: Swedbank, Danske and common Lithuanian exchange format - LITAS-ESIS. 98 | 99 | `ofxstatement-czech`_ Plugin for Poštovní spořitelna 100 | (``maxibps``) and banks using GPC 101 | format (e.g., FIO banka, module 102 | ``gpc``). 103 | 104 | `ofxstatement-airbankcz`_ Plugin for Air Bank a.s. (Czech Republic) 105 | `ofxstatement-raiffeisencz`_ Plugin for Raiffeisenbank a.s. (Czech Republic) 106 | `ofxstatement-skippaycz`_ Plugin for Skip Pay s.r.o. (Czech Republic) 107 | `ofxstatement-unicreditcz`_ Plugin for UniCredit Bank Czech Republic and Slovakia 108 | `ofxstatement-equabankcz`_ Plugin for Equa Bank a.s. (Czech Republic) 109 | `ofxstatement-cz-komercni`_ Komerční banka (Czech Republic) 110 | `ofxstatement-mbankcz`_ mBank S.A. (Czech Republic) 111 | `ofxstatement-partnersbankacz`_ Partners Banka, a.s. (Czech Republic) 112 | `ofxstatement-otp`_ Plugin for OTP Bank, operating in Hungary 113 | `ofxstatement-bubbas`_ Set of plugins, developed by @bubbas: 114 | ``dkb_cc`` and ``lbbamazon``. 115 | 116 | `banking.statements.osuuspankki`_ Finnish Osuuspankki bank 117 | `banking.statements.nordea`_ Nordea bank (at least Finnish branch of it) 118 | `ofxstatement-seb`_ SEB (Sweden), it parses Export.xlsx for private accounts 119 | `ofxstatement-lansforsakringar`_ Länsförsäkringar (Sweden), it parses Kontoutdrag.xls for private accounts 120 | 121 | `ofxstatement-be-belfius`_ Belfius (Belgium) 122 | `ofxstatement-be-keytrade`_ KeytradeBank (Belgium) 123 | `ofxstatement-be-ing`_ ING (Belgium) 124 | `ofxstatement-be-kbc`_ KBC (Belgium) 125 | `ofxstatement-be-argenta`_ Argenta (Belgium) (by @woutbr) 126 | `ofxstatement-be-argenta-nick`_ Argenta (Belgium, also supports french version) (fork by @Nick-DT) 127 | `ofxstatement-be-crelan`_ Crelan (Belgium) 128 | `ofxstatement-be-triodos`_ Belgian Triodos Bank CSV statements 129 | `ofxstatement-be-newb`_ Belgian cooperative bank newB 130 | `ofxstatement-be-vdk-fr`_ VDK (Belgium, French statements) 131 | `ofxstatement-be-hellobank-fr`_ Hello Bank (Belgium, French statements) 132 | 133 | `ofxstatement-germany`_ Plugin for several german banks (1822direkt and Postbank at the moment) 134 | `ofxstatement-dab`_ DAB Bank (Germany) 135 | `ofxstatement-consors`_ Consorsbank (Germany) 136 | `ofxstatement-de-triodos`_ German Triodos Bank CSV statements (also works for GLS Bank) 137 | `ofxstatement-sp-freiburg`_ Sparkasse Freiburg-Nördlicher Breisgau (Germany) 138 | `ofxstatement-de-ing`_ Ing Diba Bank (Germany) 139 | `ofxstatement-mastercard-de`_ Mastercard PDF statements (Germany) 140 | `ofxstatement-fidelity`_ Fidelity CSV statements 141 | `ofxstatement-sparkasse-de`_ Sparkasse PDF statements (Germany) 142 | `ofxstatement-austrian`_ Plugins for several banks, operating in Austria: 143 | Easybank, ING-Diba, Livebank, Raiffeisenbank. 144 | `ofxstatement-postfinance`_ Swiss PostFinance (E-Finance Java text based bank/credit statements). 145 | 146 | `ofxstatement-fineco`_ FinecoBank (Italy) 147 | `ofxstatement-intesasp`_ Intesa San Paolo xlsx balance file (Italy) 148 | `ofxstatement-chebanca`_ CheBanca! xlsx format (Italy) 149 | `ofxstatement-n26`_ N26 Bank (Italy) 150 | `ofxstatement-it-banks`_ Widiba and Webank (Italy) 151 | `ofxstatement-bancoposta`_ BancoPosta - Poste Italiane (Italy) 152 | `ofxstatement-hype`_ Hype - Banca Sella (Italy) 153 | 154 | `ofxstatement-betterment`_ Betterment (USA) 155 | `ofxstatement-simple`_ Simple (USA, defunct) JSON financial statement format 156 | 157 | `ofxstatement-mbank-sk`_ MBank.sk (Slovakia) 158 | `ofxstatement-latvian`_ Latvian banks 159 | `ofxstatement-ee-seb`_ SEB (Estonia), parses proprietary csv file 160 | `ofxstatement-ee-swedbank`_ Swedbank (Estonia), parses proprietary csv file 161 | `ofxstatement-polish`_ Support for some Polish banks and financial institutions 162 | `ofxstatement-russian`_ Support for several Russian banks: Avangard, AlfaBank, Tinkoff, SberBank (both debit and csv), VTB. 163 | `ofxstatement-is-arionbanki`_ Arion bank (Iceland) 164 | `ofxstatement-revolut`_ Revolut Mastercard 165 | `ofxstatement-al_bank`_ Arbejdernes Landsbank (Denmark) 166 | `ofxstatement-cd-tmb`_ Trust Merchant Bank (DRC) 167 | `ofxstatement-zm-stanbic`_ Stanbic Bank (Zambia) 168 | `ofxstatement-dutch`_ Dutch financial institutes like ICSCards and ING 169 | `ofxstatement-french`_ French financial institutes like BanquePopulaire 170 | `ofxstatement-schwab-json`_ Charles Schwab investment history JSON export 171 | `ofxstatement-bbva`_ BBVA (Spain) 172 | `ofxstatement-qif`_ Converts Quicken Interchange Format (QIF) formatted bank transaction files 173 | `ofxstatement-santander`_ Converts Santander transaction files 174 | `ofxstatement-santander-es`_ Converts Santander ES transaction files 175 | `ofxstatement-directa`_ Directa SIM Broker 176 | `ofxstatement-upday`_ UpDay 177 | ================================= ============================================ 178 | 179 | 180 | .. _ofxstatement-lithuanian: https://github.com/kedder/ofxstatement-lithuanian 181 | .. _ofxstatement-czech: https://gitlab.com/mcepl/ofxstatement-czech 182 | .. _ofxstatement-airbankcz: https://github.com/milankni/ofxstatement-airbankcz 183 | .. _ofxstatement-raiffeisencz: https://github.com/milankni/ofxstatement-raiffeisencz 184 | .. _ofxstatement-skippaycz: https://github.com/archont00/ofxstatement-skippaycz 185 | .. _ofxstatement-unicreditcz: https://github.com/milankni/ofxstatement-unicreditcz 186 | .. _ofxstatement-equabankcz: https://github.com/kosciCZ/ofxstatement-equabankcz 187 | .. _ofxstatement-mbankcz: https://github.com/SinyaWeo/ofxstatement-mbankcz 188 | .. _ofxstatement-partnersbankacz: https://github.com/archont00/ofxstatement-partnersbankacz 189 | .. _ofxstatement-otp: https://github.com/abesto/ofxstatement-otp 190 | .. _ofxstatement-bubbas: https://github.com/bubbas/ofxstatement-bubbas 191 | .. _banking.statements.osuuspankki: https://github.com/koodaamo/banking.statements.osuuspankki 192 | .. _banking.statements.nordea: https://github.com/koodaamo/banking.statements.nordea 193 | .. _ofxstatement-germany: https://github.com/MirkoDziadzka/ofxstatement-germany 194 | .. _ofxstatement-austrian: https://github.com/nblock/ofxstatement-austrian 195 | .. _ofxstatement-postfinance: https://pypi.python.org/pypi/ofxstatement-postfinance 196 | .. _ofxstatement-mbank-sk: https://github.com/epitheton/ofxstatement-mbank-sk 197 | .. _ofxstatement-be-belfius: https://github.com/renardeau/ofxstatement-be-belfius 198 | .. _ofxstatement-be-keytrade: https://github.com/Scotchy49/ofxstatement-be-keytrade 199 | .. _ofxstatement-be-ing: https://github.com/jbbandos/ofxstatement-be-ing 200 | .. _ofxstatement-be-kbc: https://github.com/plenaerts/ofxstatement-be-kbc 201 | .. _ofxstatement-be-argenta: https://github.com/woutbr/ofxstatement-be-argenta 202 | .. _ofxstatement-be-argenta-nick: https://github.com/Nick-DT/ofxstatement-be-argenta 203 | .. _ofxstatement-be-crelan: https://gitlab.com/MagnificentMoustache/ofxstatement-be.crelan 204 | .. _ofxstatement-be-newb: https://github.com/SDaron/ofxstatement-be-newb 205 | .. _ofxstatement-betterment: https://github.com/cmayes/ofxstatement-betterment 206 | .. _ofxstatement-simple: https://github.com/cmayes/ofxstatement-simple 207 | .. _ofxstatement-latvian: https://github.com/gintsmurans/ofxstatement-latvian 208 | .. _ofxstatement-iso20022: https://github.com/kedder/ofxstatement-iso20022 209 | .. _ofxstatement-seb: https://github.com/gerasiov/ofxstatement-seb 210 | .. _ofxstatement-paypal-2: https://github.com/Alfystar/ofxstatement-paypal-2 211 | .. _ofxstatement-polish: https://github.com/yay6/ofxstatement-polish 212 | .. _ofxstatement-russian: https://github.com/gerasiov/ofxstatement-russian 213 | .. _ofxstatement-dab: https://github.com/JohannesKlug/ofxstatement-dab 214 | .. _ofxstatement-consors: https://github.com/JohannesKlug/ofxstatement-consors 215 | .. _ofxstatement-is-arionbanki: https://github.com/Dagur/ofxstatement-is-arionbanki 216 | .. _ofxstatement-be-triodos: https://github.com/renardeau/ofxstatement-be-triodos 217 | .. _ofxstatement-de-triodos: https://github.com/pianoslum/ofxstatement-de-triodos 218 | .. _ofxstatement-lansforsakringar: https://github.com/lbschenkel/ofxstatement-lansforsakringar 219 | .. _ofxstatement-revolut: https://github.com/mlaitinen/ofxstatement-revolut 220 | .. _ofxstatement-transferwise: https://github.com/kedder/ofxstatement-transferwise 221 | .. _ofxstatement-n26: https://github.com/3v1n0/ofxstatement-n26 222 | .. _ofxstatement-sp-freiburg: https://github.com/omarkohl/ofxstatement-sparkasse-freiburg 223 | .. _ofxstatement-al_bank: https://github.com/lbschenkel/ofxstatement-al_bank 224 | .. _ofxstatement-fineco: https://github.com/frankIT/ofxstatement-fineco 225 | .. _ofxstatement-intesasp: https://github.com/Jacotsu/ofxstatement-intesasp 226 | .. _ofxstatement-de-ing: https://github.com/fabolhak/ofxstatement-de-ing 227 | .. _ofxstatement-germany: https://github.com/MirkoDziadzka/ofxstatement-germany 228 | .. _ofxstatement-cz-komercni: https://github.com/medovina/ofxstatement-cz-komercni 229 | .. _ofxstatement-cd-tmb: https://github.com/BIZ4Africa/ofxstatement-cd-tmb 230 | .. _ofxstatement-zm-stanbic: https://github.com/BIZ4Africa/ofxstatement-zm-stanbic 231 | .. _ofxstatement-dutch: https://github.com/gpaulissen/ofxstatement-dutch 232 | .. _ofxstatement-french: https://github.com/gpaulissen/ofxstatement-french 233 | .. _ofxstatement-mt940: https://github.com/gpaulissen/ofxstatement-mt940 234 | .. _ofxstatement-it-banks: https://github.com/ecorini/ofxstatement-it-banks 235 | .. _ofxstatement-ee-seb: https://github.com/rsi2m/ofxstatement-ee-seb 236 | .. _ofxstatement-ee-swedbank: https://github.com/rsi2m/ofxstatement-ee-swedbank 237 | .. _ofxstatement-chebanca: https://github.com/3v1n0/ofxstatement-chebanca 238 | .. _ofxstatement-mastercard-de: https://github.com/FliegendeWurst/ofxstatement-mastercard-de 239 | .. _ofxstatement-fidelity: https://github.com/mooredan/ofxstatement-fidelity 240 | .. _ofxstatement-sparkasse-de: https://github.com/FliegendeWurst/ofxstatement-sparkasse-de 241 | .. _ofxstatement-bancoposta: https://github.com/lorenzogiudici5/ofxstatement-bancoposta 242 | .. _ofxstatement-hype: https://github.com/lorenzogiudici5/ofxstatement-hype 243 | .. _ofxstatement-schwab-json: https://github.com/edwagner/ofxstatement-schwab-json 244 | .. _ofxstatement-bbva: https://github.com/3v1n0/ofxstatement-bbva 245 | .. _ofxstatement-qif: https://github.com/robvadai/ofxstatement-qif 246 | .. _ofxstatement-santander: https://github.com/robvadai/ofxstatement-santander 247 | .. _ofxstatement-santander-es: https://github.com/M3lo00/ofxstatement-santander-es 248 | .. _ofxstatement-directa: https://github.com/Alfystar/ofxstatement-directa 249 | .. _ofxstatement-upday: https://github.com/Alfystar/ofxstatement-upday 250 | .. _ofxstatement-be-vdk-fr: https://github.com/Jibuus/ofxstatement-be-vdk-fr 251 | .. _ofxstatement-be-hellobank-fr: https://github.com/Jibuus/ofxstatement-be-hellobank-fr 252 | .. _ofxstatement-nordigen: https://github.com/jstammers/ofxstatement-nordigen 253 | 254 | Advanced Configuration 255 | ====================== 256 | 257 | While ofxstatement can be used without any configuration, some plugins may 258 | accept additional configuration parameters. These parameters can be specified 259 | in a configuration file. The configuration file can be edited using the ``edit-config`` 260 | command that opens your favorite editor (defined by environment variable 261 | EDITOR or else the default for your platform) with the configuration file:: 262 | 263 | $ ofxstatement edit-config 264 | 265 | The configuration file format is in the standard .ini format. The 266 | configuration is divided into sections that correspond to the ``--type`` 267 | command line parameter. Each section must provide a ``plugin`` option that 268 | points to one of the registered conversion plugins. Other parameters are 269 | plugin specific. 270 | 271 | A sample configuration file:: 272 | 273 | [swedbank] 274 | plugin = swedbank 275 | 276 | [danske:usd] 277 | plugin = litas-esis 278 | charset = cp1257 279 | currency = USD 280 | account = LT123456789012345678 281 | 282 | 283 | Such a configuration will let ofxstatement know about two statement file 284 | formats handled by the plugins ``swedbank`` and ``litas-esis``. The ``litas-esis`` 285 | plugin will load statements using the ``cp1257`` charset and set a custom currency 286 | and account number. This way, GnuCash will automatically associate the 287 | generated .ofx file with a particular GnuCash account. 288 | 289 | To convert the proprietary CSV file ``danske.csv`` into the OFX file ``danske.ofx``, run:: 290 | 291 | $ ofxstatement -t danske:usd danske.csv danske.ofx 292 | 293 | Note that configuration parameters are plugin specific. See the plugin 294 | documentation for more info. 295 | 296 | To use a custom configuration file, pass the ``-c`` / ``--config`` option:: 297 | 298 | $ ofxstatement convert -t pluginname -c /path/to/myconfig.ini input.csv output.ofx 299 | 300 | 301 | Development / Testing 302 | ===================== 303 | 304 | ``ofxstatemnt`` uses `pipenv`_ to manage the development environment and 305 | dependencies:: 306 | 307 | $ pip install pipenv 308 | $ git clone https://github.com//ofxstatement.git 309 | $ cd ofxstatement 310 | $ pipenv sync --dev 311 | 312 | .. _pipenv: https://github.com/pypa/pipenv 313 | 314 | And finally run the test suite:: 315 | 316 | $ pipenv shell 317 | $ pytest 318 | 319 | When satisfied, you may create a pull request. 320 | 321 | Writing your own Plugin 322 | ======================= 323 | 324 | If the plugin for your bank has not been developed yet (see `Known plugins`_ 325 | section above) you can easily write your own, provided you have some knowledge 326 | about the Python programming language. There is an `ofxstatement-sample`_ 327 | plugin project available that provides sample boilerplate and describes the 328 | plugin development process in detail. 329 | 330 | .. _ofxstatement-sample: https://github.com/kedder/ofxstatement-sample 331 | -------------------------------------------------------------------------------- /doc/ofx_sample_files/ofx_spec201_invest_transactions_example.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | 0 17 | INFO 18 | 19 | 19991029101003 20 | ENG 21 | 19991029101003 22 | 19991029101003 23 | 24 | NCH 25 | 1001 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | AAPL 35 | TICKER 36 | 37 | AAPL 38 | AAPL 39 | 40 | 41 | 42 | 43 | 44 | MSFT 45 | TICKER 46 | 47 | MSFT 48 | MSFT 49 | 50 | 51 | 52 | 53 | 54 | 55 | 1002 56 | 57 | 0 58 | INFO 59 | 60 | 61 | 20210501 62 | USD 63 | 64 | Your broker name 65 | your broker account ID 66 | 67 | 68 | 20210101 69 | 20210501 70 | 71 | 72 | BUY 73 | 74 | 75 | 1234567 76 | 20210128 77 | Purchased 3 Apple (AAPL) at USD 138.28, total: USD 414.84, fees USD 1.24, transaction ID: 1234567 78 | 79 | 80 | AAPL 81 | TICKER 82 | 83 | OTHER 84 | OTHER 85 | 1.24000 86 | 138.28000 87 | 3.00000 88 | -416.08000 89 | 90 | 91 | 92 | SELL 93 | 94 | 95 | 234567 96 | 20210226 97 | Sold 5 Microsoft (MSFT) at USD 225.63, total: USD 1128.15, fees USD 0.28, transaction ID: 234567 98 | 99 | 100 | MSFT 101 | TICKER 102 | 103 | OTHER 104 | OTHER 105 | 0.28000 106 | 225.63000 107 | -5.00000 108 | 1127.87000 109 | 110 | 111 | 112 | DIV 113 | 114 | 54321 115 | 20210319 116 | Dividends from Microsoft, USD 0.79 117 | 118 | 119 | MSFT 120 | TICKER 121 | 122 | OTHER 123 | OTHER 124 | 0.79000 125 | 126 | 127 | 128 | 129 | 130 | 131 | -------------------------------------------------------------------------------- /doc/ofx_sample_files/ofx_spec201_stmtrs_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 0 6 | INFO 7 | 8 | 19991029101003 9 | ENG 10 | 19991029101003 11 | 19991029101003 12 | 13 | NCH 14 | 1001 15 | 16 | 17 | 18 | 19 | 20 | 1001 21 | 22 | 0 23 | INFO 24 | 25 | 26 | USD 27 | 28 | 121099999 29 | 999988 30 | CHECKING 31 | 32 | 34 | 19991001 35 | 19991028 36 | 37 | CHECK 38 | 19991004 39 | -200.00 40 | 00002 41 | 1000 42 | 43 | 44 | ATM 45 | 19991020 46 | 19991020 47 | -300.00 48 | 00003 49 | 50 | 51 | 52 | 200.29 53 | 199910291120 54 | 55 | 56 | 200.29 57 | 199910291120 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools>=61.0"] 3 | build-backend = "setuptools.build_meta" 4 | 5 | [project] 6 | name = "ofxstatement" 7 | version = "0.9.4.dev0" 8 | authors = [ 9 | { name="Andrey Lebedev", email="andrey@lebedev.lt" }, 10 | ] 11 | description = "Tool to convert proprietary bank statement to OFX format, suitable for importing to GnuCash" 12 | readme = "README.rst" 13 | requires-python = ">=3.9" 14 | license = {file = "LICENSE.txt"} 15 | classifiers = [ 16 | "Development Status :: 3 - Alpha", 17 | "Programming Language :: Python :: 3", 18 | "Natural Language :: English", 19 | "Topic :: Office/Business :: Financial :: Accounting", 20 | "Topic :: Utilities", 21 | "Environment :: Console", 22 | "Operating System :: OS Independent", 23 | ] 24 | keywords = ["ofx", "banking", "statement"] 25 | dependencies = [ 26 | "platformdirs", 27 | "importlib_metadata>=3.8;python_version<'3.10'", 28 | "zipp;python_version<'3.10'" 29 | ] 30 | 31 | [project.urls] 32 | Homepage = "https://github.com/kedder/ofxstatement" 33 | 34 | [project.scripts] 35 | ofxstatement = "ofxstatement.tool:run" 36 | 37 | [tool.setuptools] 38 | packages = [ 39 | "ofxstatement", 40 | "ofxstatement.plugins", 41 | "ofxstatement.tests", 42 | "ofxstatement.tests.samples", 43 | ] 44 | 45 | [tool.setuptools.package-data] 46 | ofxstatement = ["tests/samples"] 47 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | pep8: workaround for https://bitbucket.org/pytest-dev/pytest-pep8/issues/23/ 4 | 5 | python_files = 6 | test_*.py 7 | 8 | addopts = 9 | --cov ofxstatement 10 | --cov-report term-missing 11 | --no-cov-on-fail 12 | --ignore setup.py 13 | 14 | log_cli = 1 15 | log_cli_level = INFO 16 | log_cli_format = %(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s) 17 | log_cli_date_format = %Y-%m-%d %H:%M:%S 18 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [options] 2 | package_dir = =src 3 | packages = find: 4 | 5 | [options.packages.find] 6 | where = src 7 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | 3 | setup() 4 | -------------------------------------------------------------------------------- /src/ofxstatement/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedder/ofxstatement/95297cc851e5689ed11d98317d1a832af44ef9f8/src/ofxstatement/__init__.py -------------------------------------------------------------------------------- /src/ofxstatement/configuration.py: -------------------------------------------------------------------------------- 1 | from typing import Optional 2 | from collections.abc import MutableMapping 3 | import os 4 | import configparser 5 | import platformdirs 6 | 7 | from ofxstatement.exceptions import Abort 8 | 9 | APP_NAME = "ofxstatement" 10 | APP_AUTHOR = "ofx" 11 | 12 | 13 | def get_default_location() -> str: 14 | cdir = platformdirs.user_config_dir(APP_NAME, APP_AUTHOR) 15 | return os.path.join(cdir, "config.ini") 16 | 17 | 18 | def read(location: Optional[str] = None) -> Optional[MutableMapping]: 19 | if not location: 20 | location = get_default_location() 21 | 22 | if not os.path.exists(location): 23 | return None 24 | 25 | config = configparser.ConfigParser() 26 | config.read(location) 27 | return config 28 | 29 | 30 | def get_settings(config, section: str): 31 | if not config.has_section(section): 32 | raise Abort("No section named %s in config file" % section) 33 | 34 | opts = config.get_options(section) 35 | return zip([(o, config.get(section, o)) for o in opts]) 36 | -------------------------------------------------------------------------------- /src/ofxstatement/exceptions.py: -------------------------------------------------------------------------------- 1 | class Abort(Exception): 2 | pass 3 | 4 | 5 | class ParseError(Exception): 6 | """Raised by parser to indicate malformed input""" 7 | 8 | def __init__(self, lineno: int, message: str) -> None: 9 | self.lineno = lineno 10 | self.message = message 11 | 12 | 13 | class ValidationError(Exception): # pragma: no cover 14 | """Raised by parser to indicate validation errors for an object""" 15 | 16 | def __init__(self, message: str, obj: object) -> None: 17 | self.message = message 18 | self.obj = obj 19 | 20 | def __str__(self) -> str: 21 | return "message: %s; object:\n%r" % (self.message, self.obj) 22 | -------------------------------------------------------------------------------- /src/ofxstatement/ofx.py: -------------------------------------------------------------------------------- 1 | import codecs 2 | from typing import Optional, Union 3 | from datetime import datetime, date, time 4 | from decimal import Decimal 5 | 6 | from xml.etree import ElementTree as etree 7 | from xml.dom import minidom 8 | 9 | from ofxstatement.statement import ( 10 | Statement, 11 | StatementLine, 12 | InvestStatementLine, 13 | BankAccount, 14 | Currency, 15 | ) 16 | 17 | 18 | class OfxWriter(object): 19 | def __init__(self, statement: Statement) -> None: 20 | self.statement = statement 21 | self.genTime = datetime.now() 22 | self.tb = etree.TreeBuilder() 23 | self.default_float_precision = 2 24 | self.invest_transactions_float_precision = 5 25 | 26 | def toxml(self, pretty: bool = False, encoding: str = "utf-8") -> str: 27 | et = self.buildDocument() 28 | root = et.getroot() 29 | assert root is not None 30 | xmlstring = etree.tostring(root, "unicode") 31 | if pretty: 32 | dom = minidom.parseString(xmlstring) 33 | xmlstring = dom.toprettyxml(indent=" ", newl="\r\n") 34 | xmlstring = xmlstring.replace('', "").lstrip() 35 | 36 | codec = codecs.lookup(encoding) 37 | if codec.name == "utf-8": 38 | encoding_name = "UNICODE" 39 | charset_name = "NONE" 40 | elif codec.name.startswith("cp"): 41 | encoding_name = "USASCII" 42 | charset_name = codec.name[2:] 43 | else: 44 | # This is non-standard, because according to the OFX spec the 45 | # CHARSET should be the codepage number. We handle this gracefully, 46 | # since the only alternative is throwing an error here. 47 | encoding_name = "USASCII" 48 | charset_name = codec.name.upper() 49 | 50 | header = ( 51 | "OFXHEADER:100\r\n" 52 | "DATA:OFXSGML\r\n" 53 | "VERSION:102\r\n" 54 | "SECURITY:NONE\r\n" 55 | f"ENCODING:{encoding_name}\r\n" 56 | f"CHARSET:{charset_name}\r\n" 57 | "COMPRESSION:NONE\r\n" 58 | "OLDFILEUID:NONE\r\n" 59 | "NEWFILEUID:NONE\r\n" 60 | "\r\n" 61 | ) 62 | 63 | return header + xmlstring 64 | 65 | def buildDocument(self) -> etree.ElementTree: 66 | tb = self.tb 67 | tb.start("OFX", {}) 68 | 69 | self.buildSignon() 70 | 71 | self.buildTransactionList() 72 | 73 | tb.end("OFX") 74 | return etree.ElementTree(tb.close()) 75 | 76 | def buildSignon(self) -> None: 77 | tb = self.tb 78 | tb.start("SIGNONMSGSRSV1", {}) 79 | tb.start("SONRS", {}) 80 | tb.start("STATUS", {}) 81 | self.buildText("CODE", "0") 82 | self.buildText("SEVERITY", "INFO") 83 | tb.end("STATUS") 84 | 85 | self.buildDateTime("DTSERVER", self.genTime) 86 | self.buildText("LANGUAGE", "ENG") 87 | 88 | tb.end("SONRS") 89 | tb.end("SIGNONMSGSRSV1") 90 | 91 | def buildTransactionList(self) -> None: 92 | if self.statement.lines: 93 | self.buildBankTransactionList() 94 | 95 | if self.statement.invest_lines: 96 | self.buildInvestTransactionList() 97 | 98 | def buildBankTransactionList(self) -> None: 99 | tb = self.tb 100 | tb.start("BANKMSGSRSV1", {}) 101 | tb.start("STMTTRNRS", {}) 102 | 103 | self.buildText("TRNUID", "0") 104 | tb.start("STATUS", {}) 105 | self.buildText("CODE", "0") 106 | self.buildText("SEVERITY", "INFO") 107 | tb.end("STATUS") 108 | 109 | tb.start("STMTRS", {}) 110 | self.buildText("CURDEF", self.statement.currency) 111 | tb.start("BANKACCTFROM", {}) 112 | self.buildText("BANKID", self.statement.bank_id, False) 113 | self.buildText("BRANCHID", self.statement.branch_id) 114 | self.buildText("ACCTID", self.statement.account_id, False) 115 | self.buildText("ACCTTYPE", self.statement.account_type) 116 | tb.end("BANKACCTFROM") 117 | 118 | tb.start("BANKTRANLIST", {}) 119 | self.buildDateTime("DTSTART", self.statement.start_date, False, True) 120 | self.buildDateTime("DTEND", self.statement.end_date, False, True) 121 | 122 | for line in self.statement.lines: 123 | self.buildBankTransaction(line) 124 | 125 | tb.end("BANKTRANLIST") 126 | 127 | tb.start("LEDGERBAL", {}) 128 | self.buildAmount("BALAMT", self.statement.end_balance, False) 129 | self.buildDateTime("DTASOF", self.statement.end_date, False) 130 | tb.end("LEDGERBAL") 131 | 132 | tb.end("STMTRS") 133 | tb.end("STMTTRNRS") 134 | tb.end("BANKMSGSRSV1") 135 | 136 | def buildBankTransaction(self, line: StatementLine) -> None: 137 | tb = self.tb 138 | tb.start("STMTTRN", {}) 139 | 140 | self.buildText("TRNTYPE", line.trntype) 141 | self.buildDateTime("DTPOSTED", line.date, omitEmptyTime=True) 142 | self.buildDateTime("DTUSER", line.date_user, omitEmptyTime=True) 143 | self.buildAmount("TRNAMT", line.amount) 144 | self.buildText("FITID", line.id) 145 | self.buildText("CHECKNUM", line.check_no) 146 | self.buildText("REFNUM", line.refnum) 147 | self.buildText("NAME", line.payee) 148 | if line.bank_account_to: 149 | tb.start("BANKACCTTO", {}) 150 | self.buildBankAccount(line.bank_account_to) 151 | tb.end("BANKACCTTO") 152 | self.buildText("MEMO", line.memo) 153 | if line.currency is not None: 154 | self.buildCurrency("CURRENCY", line.currency) 155 | if line.orig_currency is not None: 156 | self.buildCurrency("ORIGCURRENCY", line.orig_currency) 157 | 158 | tb.end("STMTTRN") 159 | 160 | def buildCurrency(self, tag: str, currency: Currency) -> None: 161 | self.tb.start(tag, {}) 162 | self.buildText("CURSYM", currency.symbol) 163 | self.buildAmount("CURRATE", currency.rate, precision=4) 164 | self.tb.end(tag) 165 | 166 | def buildInvestTransactionList(self) -> None: 167 | tb = self.tb 168 | tb.start("SECLISTMSGSRSV1", {}) 169 | tb.start("SECLIST", {}) 170 | 171 | # get unqiue tickers 172 | for security_id in dict.fromkeys( 173 | map(lambda x: x.security_id, self.statement.invest_lines) 174 | ): 175 | if security_id is None: 176 | continue 177 | tb.start("STOCKINFO", {}) 178 | tb.start("SECINFO", {}) 179 | tb.start("SECID", {}) 180 | self.buildText("UNIQUEID", security_id) 181 | self.buildText("UNIQUEIDTYPE", "TICKER") 182 | tb.end("SECID") 183 | self.buildText("SECNAME", security_id) 184 | self.buildText("TICKER", security_id) 185 | tb.end("SECINFO") 186 | tb.end("STOCKINFO") 187 | 188 | tb.end("SECLIST") 189 | tb.end("SECLISTMSGSRSV1") 190 | 191 | tb.start("INVSTMTMSGSRSV1", {}) 192 | tb.start("INVSTMTTRNRS", {}) 193 | 194 | self.buildText("TRNUID", "0") 195 | tb.start("STATUS", {}) 196 | self.buildText("CODE", "0") 197 | self.buildText("SEVERITY", "INFO") 198 | tb.end("STATUS") 199 | 200 | tb.start("INVSTMTRS", {}) 201 | self.buildDateTime("DTASOF", self.statement.end_date, False) 202 | self.buildText("CURDEF", self.statement.currency) 203 | tb.start("INVACCTFROM", {}) 204 | self.buildText("BROKERID", self.statement.broker_id, False) 205 | self.buildText("ACCTID", self.statement.account_id, False) 206 | tb.end("INVACCTFROM") 207 | 208 | tb.start("INVTRANLIST", {}) 209 | self.buildDateTime("DTSTART", self.statement.start_date, False, True) 210 | self.buildDateTime("DTEND", self.statement.end_date, False, True) 211 | 212 | for line in self.statement.invest_lines: 213 | self.buildInvestTransaction(line) 214 | 215 | tb.end("INVTRANLIST") 216 | tb.end("INVSTMTRS") 217 | tb.end("INVSTMTTRNRS") 218 | tb.end("INVSTMTMSGSRSV1") 219 | 220 | def buildInvestTransaction(self, line: InvestStatementLine) -> None: 221 | # invest transactions must always have trntype 222 | if line.trntype is None: 223 | return 224 | 225 | tb = self.tb 226 | 227 | if line.trntype == "INVBANKTRAN": 228 | tb.start(line.trntype, {}) 229 | bankTran = StatementLine(line.id, line.date, line.memo, line.amount) 230 | bankTran.trntype = line.trntype_detailed 231 | self.buildBankTransaction(bankTran) 232 | self.buildText("SUBACCTFUND", "OTHER") 233 | tb.end(line.trntype) 234 | return 235 | 236 | tran_type_detailed_tag_name = None 237 | inner_tran_type_tag_name = None 238 | if line.trntype.startswith("BUY"): 239 | inner_tran_type_tag_name = "INVBUY" 240 | if line.trntype == "BUYMF" or line.trntype == "BUYSTOCK": 241 | tran_type_detailed_tag_name = "BUYTYPE" 242 | elif line.trntype.startswith("SELL"): 243 | inner_tran_type_tag_name = "INVSELL" 244 | if line.trntype == "SELLMF" or line.trntype == "SELLSTOCK": 245 | tran_type_detailed_tag_name = "SELLTYPE" 246 | elif line.trntype == "INCOME": 247 | tran_type_detailed_tag_name = "INCOMETYPE" 248 | inner_tran_type_tag_name = ( 249 | None # income transactions don't have an envelope element 250 | ) 251 | else: 252 | # INVEXPENSE and TRANSFER transactions don't have details or an envelope 253 | tran_type_detailed_tag_name = None 254 | inner_tran_type_tag_name = None 255 | 256 | tb.start(line.trntype, {}) 257 | if tran_type_detailed_tag_name: 258 | self.buildText(tran_type_detailed_tag_name, line.trntype_detailed, False) 259 | 260 | if inner_tran_type_tag_name: 261 | tb.start(inner_tran_type_tag_name, {}) 262 | 263 | tb.start("INVTRAN", {}) 264 | self.buildText("FITID", line.id) 265 | self.buildDateTime("DTTRADE", line.date, False, True) 266 | self.buildText("MEMO", line.memo) 267 | tb.end("INVTRAN") 268 | 269 | tb.start("SECID", {}) 270 | self.buildText("UNIQUEID", line.security_id, False) 271 | self.buildText("UNIQUEIDTYPE", "TICKER") 272 | tb.end("SECID") 273 | 274 | self.buildText("SUBACCTSEC", "OTHER") 275 | if line.trntype != "TRANSFER": 276 | self.buildText("SUBACCTFUND", "OTHER") 277 | 278 | if line.fees: 279 | if line.trntype == "INCOME": 280 | self.buildAmount( 281 | "WITHHOLDING", 282 | line.fees, 283 | False, 284 | precision=self.invest_transactions_float_precision, 285 | ) 286 | else: 287 | self.buildAmount( 288 | "FEES", 289 | line.fees, 290 | False, 291 | precision=self.invest_transactions_float_precision, 292 | ) 293 | 294 | self.buildAmount( 295 | "UNITPRICE", 296 | line.unit_price, 297 | precision=self.invest_transactions_float_precision, 298 | ) 299 | self.buildAmount( 300 | "UNITS", 301 | line.units, 302 | precision=self.invest_transactions_float_precision, 303 | ) 304 | 305 | self.buildAmount("TOTAL", line.amount) 306 | 307 | if inner_tran_type_tag_name: 308 | tb.end(inner_tran_type_tag_name) 309 | tb.end(line.trntype) 310 | 311 | def buildBankAccount(self, account: BankAccount) -> None: 312 | self.buildText("BANKID", account.bank_id) 313 | self.buildText("BRANCHID", account.branch_id) 314 | self.buildText("ACCTID", account.acct_id) 315 | self.buildText("ACCTTYPE", account.acct_type) 316 | self.buildText("ACCTKEY", account.acct_key) 317 | 318 | def buildText(self, tag: str, text: Optional[str], skipEmpty: bool = True) -> None: 319 | if not text and skipEmpty: 320 | return 321 | self.tb.start(tag, {}) 322 | self.tb.data(text or "") 323 | self.tb.end(tag) 324 | 325 | def buildDateTime( 326 | self, 327 | tag: str, 328 | dt: Optional[datetime], 329 | skipEmpty: bool = True, 330 | omitEmptyTime=False, 331 | ) -> None: 332 | if not dt and skipEmpty: 333 | return 334 | if dt is None: 335 | self.buildText(tag, "", skipEmpty) 336 | else: 337 | utc_offset = dt.utcoffset() 338 | 339 | format = "%Y%m%d" 340 | if dt.time() != time.min or utc_offset or not omitEmptyTime: 341 | format += "%H%M%S" 342 | if dt.microsecond or utc_offset: 343 | format += f".{(dt.microsecond // 1000):03d}" 344 | if utc_offset is not None: 345 | format += f"[{utc_offset.total_seconds() / 3600}]" 346 | self.buildText(tag, dt.strftime(format)) 347 | 348 | def buildAmount( 349 | self, 350 | tag: str, 351 | amount: Optional[Decimal], 352 | skipEmpty: bool = True, 353 | precision: Optional[int] = None, 354 | ) -> None: 355 | if amount is None and skipEmpty: 356 | return 357 | if amount is None: 358 | self.buildText(tag, "", skipEmpty) 359 | else: 360 | if precision is None: 361 | precision = self.default_float_precision 362 | 363 | self.buildText(tag, "{0:.{precision}f}".format(amount, precision=precision)) 364 | -------------------------------------------------------------------------------- /src/ofxstatement/parser.py: -------------------------------------------------------------------------------- 1 | from typing import Dict, Optional, Any, Iterable, List, TextIO, TypeVar, Generic 2 | from abc import abstractmethod 3 | import csv 4 | from decimal import Decimal, Decimal as D 5 | from datetime import datetime 6 | 7 | from ofxstatement.statement import Statement, StatementLine 8 | 9 | LT = TypeVar("LT") 10 | 11 | 12 | class AbstractStatementParser: 13 | @abstractmethod 14 | def parse(self) -> Statement: 15 | """Parse the input and produce the statement object""" 16 | 17 | 18 | class StatementParser(AbstractStatementParser, Generic[LT]): 19 | """Abstract statement parser. 20 | 21 | Defines interface for all parser implementation 22 | """ 23 | 24 | statement: Statement 25 | 26 | date_format: str = "%Y-%m-%d" 27 | cur_record: int = 0 28 | 29 | def __init__(self) -> None: 30 | self.statement = Statement() 31 | 32 | def parse(self) -> Statement: 33 | """Read and parse statement 34 | 35 | Return Statement object 36 | 37 | May raise exceptions.ParseException on malformed input. 38 | """ 39 | assert hasattr(self, "statement"), "StatementParser.__init__() not called" 40 | 41 | reader = self.split_records() 42 | for line in reader: 43 | self.cur_record += 1 44 | if not line: 45 | continue 46 | stmt_line = self.parse_record(line) 47 | if stmt_line: 48 | stmt_line.assert_valid() 49 | self.statement.lines.append(stmt_line) 50 | return self.statement 51 | 52 | def split_records(self) -> Iterable[LT]: # pragma: no cover 53 | """Return iterable object consisting of a line per transaction""" 54 | raise NotImplementedError 55 | 56 | def parse_record(self, line: LT) -> Optional[StatementLine]: # pragma: no cover 57 | """Parse given transaction line and return StatementLine object""" 58 | raise NotImplementedError 59 | 60 | def parse_value(self, value: Optional[str], field: str) -> Any: 61 | tp = StatementLine.__annotations__.get(field) 62 | if value is None: 63 | return None 64 | 65 | if tp in (datetime, Optional[datetime]): 66 | return self.parse_datetime(value) 67 | elif tp in (Decimal, Optional[Decimal]): 68 | return self.parse_decimal(value) 69 | else: 70 | return value 71 | 72 | def parse_datetime(self, value: str) -> datetime: 73 | return datetime.strptime(value, self.date_format) 74 | 75 | def parse_float(self, value: str) -> D: # pragma: no cover 76 | # compatibility wrapper for old plugins 77 | return self.parse_decimal(value) 78 | 79 | def parse_decimal(self, value: str) -> D: 80 | # some plugins pass localised numbers, clean them up 81 | return D(value.replace(",", ".").replace(" ", "")) 82 | 83 | 84 | class CsvStatementParser(StatementParser[List[str]]): 85 | """Generic csv statement parser""" 86 | 87 | fin: TextIO # file input stream 88 | 89 | # 0-based csv column mapping to StatementLine field 90 | mappings: Dict[str, int] = {} 91 | 92 | def __init__(self, fin: TextIO) -> None: 93 | super().__init__() 94 | self.fin = fin 95 | 96 | def split_records(self) -> Iterable[List[str]]: 97 | return csv.reader(self.fin) 98 | 99 | def parse_record(self, line: List[str]) -> Optional[StatementLine]: 100 | stmt_line = StatementLine() 101 | for field, col in self.mappings.items(): 102 | if col >= len(line): 103 | raise ValueError( 104 | "Cannot find column %s in line of %s items " % (col, len(line)) 105 | ) 106 | rawvalue = line[col] 107 | value = self.parse_value(rawvalue, field) 108 | setattr(stmt_line, field, value) 109 | return stmt_line 110 | -------------------------------------------------------------------------------- /src/ofxstatement/plugin.py: -------------------------------------------------------------------------------- 1 | """Plugin framework. 2 | 3 | Plugins are objects that configures and coordinates conversion machinery. 4 | """ 5 | 6 | from typing import List, Tuple, Type 7 | from collections.abc import MutableMapping 8 | import sys 9 | 10 | if sys.version_info < (3, 10): 11 | from importlib_metadata import entry_points 12 | else: 13 | from importlib.metadata import entry_points 14 | 15 | from ofxstatement.ui import UI 16 | from ofxstatement.parser import AbstractStatementParser 17 | 18 | 19 | def get_plugin(name: str, ui: UI, settings: MutableMapping) -> "Plugin": 20 | plugins = entry_points(name=name) 21 | if not plugins: 22 | raise PluginNotRegistered(name) 23 | if len(plugins) > 1: 24 | raise PluginNameConflict(plugins) 25 | plugin = plugins[name].load() 26 | return plugin(ui, settings) 27 | 28 | 29 | def list_plugins() -> List[Tuple[str, Type["Plugin"]]]: 30 | """Return list of all plugin classes registered as a list of tuples: 31 | 32 | [(name, plugin_class)] 33 | """ 34 | plugin_eps = entry_points(group="ofxstatement") 35 | return sorted((ep.name, ep.load()) for ep in plugin_eps) 36 | 37 | 38 | class PluginNotRegistered(Exception): 39 | """Raised on attempt to get plugin, missing from the registry.""" 40 | 41 | 42 | class PluginNameConflict(Exception): 43 | """Raised when there are more than one plugins registered with the same 44 | name 45 | """ 46 | 47 | 48 | class Plugin: 49 | ui: UI 50 | 51 | def __init__(self, ui: UI, settings: MutableMapping) -> None: 52 | self.ui = ui 53 | self.settings = settings 54 | 55 | def get_parser(self, filename: str) -> AbstractStatementParser: 56 | raise NotImplementedError() 57 | -------------------------------------------------------------------------------- /src/ofxstatement/plugins/README.txt: -------------------------------------------------------------------------------- 1 | Namespace package for ofxstatement plugins 2 | 3 | Please do not remove this file. -------------------------------------------------------------------------------- /src/ofxstatement/plugins/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedder/ofxstatement/95297cc851e5689ed11d98317d1a832af44ef9f8/src/ofxstatement/plugins/__init__.py -------------------------------------------------------------------------------- /src/ofxstatement/py.typed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedder/ofxstatement/95297cc851e5689ed11d98317d1a832af44ef9f8/src/ofxstatement/py.typed -------------------------------------------------------------------------------- /src/ofxstatement/statement.py: -------------------------------------------------------------------------------- 1 | """Statement model""" 2 | 3 | from typing import List, Optional 4 | from datetime import datetime 5 | from decimal import Decimal as D 6 | from hashlib import sha1 7 | from pprint import pformat 8 | from math import isclose 9 | 10 | from ofxstatement import exceptions 11 | 12 | # See section 11.4.4.3 of the OFX spec v2.3 13 | STMTTRN_TRNTYPES = [ 14 | "CREDIT", # Generic credit 15 | "DEBIT", # Generic debit 16 | "INT", # Interest earned or paid 17 | "DIV", # Dividend 18 | "FEE", # FI fee 19 | "SRVCHG", # Service charge 20 | "DEP", # Deposit 21 | "ATM", # ATM debit or credit 22 | "POS", # Point of sale debit or credit 23 | "XFER", # Transfer 24 | "CHECK", # Check 25 | "PAYMENT", # Electronic payment 26 | "CASH", # Cash withdrawal 27 | "DIRECTDEP", # Direct deposit 28 | "DIRECTDEBIT", # Merchant initiated debit 29 | "REPEATPMT", # Repeating payment/standing order 30 | "OTHER", # Other 31 | ] 32 | 33 | # See section 13.9.2.4.4 of the OFX spec v2.3 34 | INVEST_TRANSACTION_TYPES = [ 35 | "BUYDEBT", 36 | "BUYMF", 37 | "BUYSTOCK", 38 | "INCOME", 39 | "INVEXPENSE", 40 | "INVBANKTRAN", 41 | "SELLDEBT", 42 | "SELLMF", 43 | "SELLSTOCK", 44 | "TRANSFER", 45 | ] 46 | 47 | # Buy/sell/income types from section 13.9.2.4.2 of the OFX spec v2.3 48 | INVEST_TRANSACTION_BUYTYPES = [ 49 | "BUY", 50 | "BUYTOCOVER", # end short sale 51 | ] 52 | 53 | INVEST_TRANSACTION_SELLTYPES = [ 54 | "SELL", 55 | "SELLSHORT", # open short sale 56 | ] 57 | 58 | INVEST_TRANSACTION_INCOMETYPES = [ 59 | "CGLONG", 60 | "CGSHORT", 61 | "DIV", 62 | "INTEREST", 63 | "MISC", 64 | ] 65 | 66 | ACCOUNT_TYPE = [ 67 | "CHECKING", # Checking 68 | "SAVINGS", # Savings 69 | "MONEYMRKT", # Money Market 70 | "CREDITLINE", # Line of credit 71 | ] 72 | 73 | 74 | # Inspired by "How to print instances of a class using print()?" 75 | # on stackoverflow.com 76 | class Printable: 77 | def __repr__(self) -> str: # pragma: no cover 78 | # do not set width to 1 because that makes the output really ugly 79 | return "<" + type(self).__name__ + "> " + pformat(vars(self), indent=4) 80 | 81 | 82 | class Statement(Printable): 83 | """Statement object containing statement items""" 84 | 85 | lines: List["StatementLine"] 86 | invest_lines: List["InvestStatementLine"] 87 | 88 | currency: Optional[str] = None 89 | bank_id: Optional[str] = None 90 | branch_id: Optional[str] = None 91 | broker_id: Optional[str] = None 92 | account_id: Optional[str] = None 93 | # Type of account, must be one of ACCOUNT_TYPE 94 | account_type: Optional[str] = None 95 | 96 | start_balance: Optional[D] = None 97 | start_date: Optional[datetime] = None 98 | 99 | end_balance: Optional[D] = None 100 | end_date: Optional[datetime] = None 101 | 102 | def __init__( 103 | self, 104 | bank_id: Optional[str] = None, 105 | account_id: Optional[str] = None, 106 | currency: Optional[str] = None, 107 | account_type: str = "CHECKING", 108 | branch_id: Optional[str] = None, 109 | ) -> None: 110 | self.lines = [] 111 | self.invest_lines = [] 112 | self.bank_id = bank_id 113 | self.branch_id = branch_id 114 | self.account_id = account_id 115 | self.currency = currency 116 | self.account_type = account_type 117 | 118 | def assert_valid(self) -> None: # pragma: no cover 119 | if not (self.start_balance is None or self.end_balance is None): 120 | total_amount = sum( 121 | [sl.amount for sl in self.lines if sl.amount is not None], D(0) 122 | ) 123 | 124 | msg = ( 125 | "Start balance ({0}) plus the total amount ({1}) " 126 | "should be equal to the end balance ({2})".format( 127 | self.start_balance, total_amount, self.end_balance 128 | ) 129 | ) 130 | if not isclose(self.start_balance + total_amount, self.end_balance): 131 | raise exceptions.ValidationError(msg, self) 132 | 133 | 134 | class StatementLine(Printable): 135 | """Statement line data.""" 136 | 137 | id: Optional[str] 138 | # Date transaction was posted to account 139 | date: Optional[datetime] 140 | memo: Optional[str] 141 | 142 | # Amount of transaction 143 | amount: Optional[D] 144 | 145 | # additional fields 146 | payee: Optional[str] 147 | 148 | # Date user initiated transaction, if known 149 | date_user: Optional[datetime] 150 | 151 | # Check (or other reference) number 152 | check_no: Optional[str] 153 | 154 | # Reference number that uniquely identifies the transaction. Can be used in 155 | # addition to or instead of a check_no 156 | refnum: Optional[str] 157 | 158 | # Transaction type, must be one of STMTTRN_TRNTYPES 159 | trntype: Optional[str] = "CHECK" 160 | 161 | # Optional BankAccount instance 162 | bank_account_to: Optional["BankAccount"] = None 163 | 164 | # Currency this line is expressed in (if different from statement 165 | # currency). Available since 0.7.2 166 | currency: Optional["Currency"] = None 167 | 168 | # Original amount and the original (foreign) currency. Available since 0.7.2 169 | orig_currency: Optional["Currency"] = None 170 | 171 | def __init__( 172 | self, 173 | id: Optional[str] = None, 174 | date: Optional[datetime] = None, 175 | memo: Optional[str] = None, 176 | amount: Optional[D] = None, 177 | ) -> None: 178 | self.id = id 179 | self.date = date 180 | self.memo = memo 181 | self.amount = amount 182 | 183 | self.date_user = None 184 | self.payee = None 185 | self.check_no = None 186 | self.refnum = None 187 | 188 | def __str__(self) -> str: # pragma: no cover 189 | return """ 190 | ID: %s, date: %s, amount: %s, payee: %s 191 | memo: %s 192 | check no.: %s 193 | """ % ( 194 | self.id, 195 | self.date, 196 | self.amount, 197 | self.payee, 198 | self.memo, 199 | self.check_no, 200 | ) 201 | 202 | def assert_valid(self) -> None: 203 | """Ensure that fields have valid values""" 204 | assert ( 205 | self.trntype in STMTTRN_TRNTYPES 206 | ), "trntype %s is not valid, must be one of %s" % ( 207 | self.trntype, 208 | STMTTRN_TRNTYPES, 209 | ) 210 | 211 | if self.bank_account_to: 212 | self.bank_account_to.assert_valid() 213 | 214 | assert self.id or self.check_no or self.refnum 215 | 216 | 217 | class Currency(Printable): 218 | """CURRENCY and ORIGCURRENCY aggregates from OFX 219 | 220 | See section 5.2 from OFX spec version 2.2. 221 | """ 222 | 223 | # ISO-4217 3-letter currency identifier 224 | symbol: str 225 | # Ratio of statement currency to `symbol` currency 226 | rate: Optional[D] 227 | 228 | def __init__(self, symbol: str, rate: Optional[D] = None) -> None: 229 | self.symbol = symbol 230 | self.rate = rate 231 | 232 | 233 | class InvestStatementLine(Printable): 234 | """Invest statement line data.""" 235 | 236 | id: Optional[str] 237 | # Date transaction was posted to account 238 | date: Optional[datetime] 239 | memo: Optional[str] 240 | 241 | # ID or ticker of underlying security 242 | security_id: Optional[str] 243 | # Transaction type, must be one of INVEST_TRANSACTION_TYPES 244 | trntype: Optional[str] 245 | # More detailed information about transaction, must be one of INVEST_TRANSACTION_TYPES_DETAILED 246 | trntype_detailed: Optional[str] 247 | 248 | # Amount of transaction 249 | amount: Optional[D] 250 | fees: Optional[D] = None 251 | unit_price: Optional[D] = None # required for buy/sell transactions 252 | units: Optional[D] = None # required for buy/sell transactions 253 | 254 | def __init__( 255 | self, 256 | id: Optional[str] = None, 257 | date: Optional[datetime] = None, 258 | memo: Optional[str] = None, 259 | trntype: Optional[str] = None, 260 | trntype_detailed: Optional[str] = None, 261 | security_id: Optional[str] = None, 262 | amount: Optional[D] = None, 263 | ) -> None: 264 | self.id = id 265 | self.date = date 266 | self.memo = memo 267 | self.trntype = trntype 268 | self.trntype_detailed = trntype_detailed 269 | self.security_id = security_id 270 | self.amount = amount 271 | 272 | def __str__(self) -> str: 273 | return """ 274 | ID: %s, date: %s, trntype: %s, trntype_detailed: %s, security_id: %s, units: %s, unit_price: %s, amount: %s, fees: %s 275 | memo: %s 276 | """ % ( 277 | self.id, 278 | self.date, 279 | self.trntype, 280 | self.trntype_detailed, 281 | self.security_id, 282 | self.units, 283 | self.unit_price, 284 | self.amount, 285 | self.fees, 286 | self.memo, 287 | ) 288 | 289 | def assert_valid(self) -> None: 290 | """Ensure that fields have valid values""" 291 | # Every transaction needs an ID and date 292 | assert self.id 293 | assert self.date 294 | 295 | # Each transaction type has slightly different requirements 296 | if self.trntype == "BUYDEBT": 297 | self.assert_valid_buydebt() 298 | if self.trntype == "BUYMF" or self.trntype == "BUYSTOCK": 299 | self.assert_valid_buystock() 300 | elif self.trntype == "INCOME": 301 | self.assert_valid_income() 302 | elif self.trntype == "INVBANKTRAN": 303 | self.assert_valid_invbanktran() 304 | elif self.trntype == "INVEXPENSE": 305 | self.assert_valid_invexpense() 306 | elif self.trntype == "SELLDEBT": 307 | self.assert_valid_selldebt() 308 | elif self.trntype == "SELLMF" or self.trntype == "SELLSTOCK": 309 | self.assert_valid_sellstock() 310 | elif self.trntype == "TRANSFER": 311 | self.assert_valid_transfer() 312 | else: 313 | raise AssertionError( 314 | "trntype %s is not valid, must be one of %s" 315 | % ( 316 | self.trntype, 317 | INVEST_TRANSACTION_TYPES, 318 | ) 319 | ) 320 | 321 | def assert_valid_buydebt(self): 322 | assert ( 323 | self.trntype_detailed is None 324 | ), f"trntype_detailed '{self.trntype_detailed}' should be empty for {self.trntype}" 325 | self.assert_valid_invbuy() 326 | 327 | def assert_valid_buystock(self): 328 | assert ( 329 | self.trntype_detailed in INVEST_TRANSACTION_BUYTYPES 330 | ), "trntype_detailed %s is not valid, must be one of %s" % ( 331 | self.trntype_detailed, 332 | INVEST_TRANSACTION_BUYTYPES, 333 | ) 334 | self.assert_valid_invbuy() 335 | 336 | def assert_valid_income(self): 337 | assert ( 338 | self.trntype_detailed in INVEST_TRANSACTION_INCOMETYPES 339 | ), "trntype_detailed %s is not valid, must be one of %s" % ( 340 | self.trntype_detailed, 341 | INVEST_TRANSACTION_INCOMETYPES, 342 | ) 343 | assert self.security_id 344 | assert self.amount 345 | 346 | def assert_valid_invbanktran(self): 347 | assert ( 348 | self.trntype_detailed in STMTTRN_TRNTYPES 349 | ), "trntype_detailed %s is not valid for INVBANKTRAN, must be one of %s" % ( 350 | self.trntype_detailed, 351 | STMTTRN_TRNTYPES, 352 | ) 353 | assert self.amount 354 | 355 | def assert_valid_invexpense(self): 356 | assert ( 357 | self.trntype_detailed is None 358 | ), f"trntype_detailed '{self.trntype_detailed}' should be empty for {self.trntype}" 359 | assert self.security_id 360 | assert self.amount 361 | 362 | def assert_valid_selldebt(self): 363 | assert ( 364 | self.trntype_detailed is None 365 | ), f"trntype_detailed '{self.trntype_detailed}' should be empty for {self.trntype}" 366 | self.assert_valid_invsell() 367 | 368 | def assert_valid_sellstock(self): 369 | assert ( 370 | self.trntype_detailed in INVEST_TRANSACTION_SELLTYPES 371 | ), "trntype_detailed %s is not valid, must be one of %s" % ( 372 | self.trntype_detailed, 373 | INVEST_TRANSACTION_SELLTYPES, 374 | ) 375 | self.assert_valid_invsell() 376 | 377 | def assert_valid_transfer(self): 378 | assert ( 379 | self.trntype_detailed is None 380 | ), f"trntype_detailed '{self.trntype_detailed}' should be empty for {self.trntype}" 381 | assert self.security_id 382 | assert self.units 383 | 384 | def assert_valid_invbuy(self): 385 | assert self.security_id 386 | assert self.units 387 | assert self.unit_price 388 | assert self.amount 389 | 390 | def assert_valid_invsell(self): 391 | assert self.security_id 392 | assert self.units 393 | assert self.unit_price 394 | assert self.amount 395 | 396 | 397 | class BankAccount(Printable): 398 | """Structure corresponding to BANKACCTTO and BANKACCTFROM elements from OFX 399 | 400 | Open Financial Exchange uses the Banking Account aggregate to identify an 401 | account at an FI. The aggregate contains enough information to uniquely 402 | identify an account for the purposes of statement. 403 | """ 404 | 405 | # Routing and transit number 406 | bank_id: str 407 | # Bank identifier for international banks 408 | branch_id: Optional[str] = None 409 | # Account number 410 | acct_id: str 411 | # Type of account, must be one of ACCOUNT_TYPE 412 | acct_type: str 413 | # Checksum for international banks 414 | acct_key: Optional[str] = None 415 | 416 | def __init__(self, bank_id: str, acct_id: str, acct_type: str = "CHECKING") -> None: 417 | self.bank_id = bank_id 418 | self.acct_id = acct_id 419 | self.acct_type = acct_type 420 | 421 | self.branch_id = None 422 | self.acct_key = None 423 | 424 | def assert_valid(self) -> None: 425 | assert self.acct_type in ACCOUNT_TYPE, ( 426 | "acct_type must be one of %s" % ACCOUNT_TYPE 427 | ) 428 | 429 | 430 | def generate_transaction_id(stmt_line: StatementLine) -> str: 431 | """Generate pseudo-unique id for given statement line. 432 | 433 | This function can be used in statement parsers when real transaction id is 434 | not available in source statement. 435 | """ 436 | h = sha1() 437 | assert stmt_line.date is not None 438 | h.update(stmt_line.date.strftime("%Y-%m-%d %H:%M:%S").encode("utf8")) 439 | if stmt_line.memo is not None: 440 | h.update(stmt_line.memo.encode("utf8")) 441 | if stmt_line.amount is not None: 442 | h.update(str(stmt_line.amount).encode("utf8")) 443 | return h.hexdigest() 444 | 445 | 446 | def generate_unique_transaction_id(stmt_line: StatementLine, unique_id_set: set) -> str: 447 | """ 448 | Generate a unique transaction id. 449 | 450 | A bit of background: the problem with these transaction id's is that 451 | they do do not only have to be unique, they also have to stay the same 452 | for the same transaction every time you generate the statement. So 453 | generating random ids will not work, even though they will be unique, 454 | GnuCash or beancount will recognize these transaction as "new" if you 455 | happen to generate and import the same statement twice or import two 456 | statements with overlapping periods. 457 | 458 | The function generate_transaction_id() is deterministic, but does not 459 | necesserily generate an unique id. 460 | 461 | Therefore this function improves on it since you can create a 462 | really unique id by adding an increment to the generated id (a string) 463 | and keep on incrementing till it succeeds. 464 | 465 | These are the steps: 466 | 1) supply a unique id set you want to use for checking uniqueness 467 | 2) next you generate an initial id by calling 468 | generate_transaction_id() 469 | 3) assign the initial id to the current id (id) 470 | 4) increment a counter while the current id is a member of the set and 471 | add the counter to the initial id and assign that to the current id 472 | 5) add the current id to the unique id set 473 | 6) return a list of the current id and the counter (if not 0) 474 | 475 | The counter is returned in order to enable the caller to modify 476 | its statement line, for example the memo field. 477 | """ 478 | # Save the initial id 479 | id = initial_id = generate_transaction_id(stmt_line) 480 | counter = 0 481 | while id in unique_id_set: 482 | counter += 1 483 | id = initial_id + str(counter) 484 | 485 | unique_id_set.add(id) 486 | return id + ("" if counter == 0 else "-" + str(counter)) 487 | 488 | 489 | def recalculate_balance(stmt: Statement) -> None: 490 | """Recalculate statement starting and ending dates and balances. 491 | 492 | When starting balance is not available, it will be assumed to be 0. 493 | 494 | This function can be used in statement parsers when balance information is 495 | not available in source statement. 496 | """ 497 | 498 | total_amount = sum([sl.amount for sl in stmt.lines if sl.amount is not None], D(0)) 499 | 500 | stmt.start_balance = stmt.start_balance or D(0) 501 | stmt.end_balance = stmt.start_balance + total_amount 502 | stmt.start_date = min(sl.date for sl in stmt.lines if sl.date is not None) 503 | stmt.end_date = max(sl.date for sl in stmt.lines if sl.date is not None) 504 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kedder/ofxstatement/95297cc851e5689ed11d98317d1a832af44ef9f8/src/ofxstatement/tests/__init__.py -------------------------------------------------------------------------------- /src/ofxstatement/tests/samples/config.ini: -------------------------------------------------------------------------------- 1 | [swedbank] 2 | plugin = swedbank 3 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_configuration.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | 4 | from ofxstatement import configuration 5 | from ofxstatement.exceptions import Abort 6 | 7 | 8 | class ConfigurationTest(unittest.TestCase): 9 | def test_configuration(self) -> None: 10 | here = os.path.dirname(__file__) 11 | cfname = os.path.join(here, "samples", "config.ini") 12 | config = configuration.read(cfname) 13 | assert config is not None 14 | self.assertEqual(config["swedbank"]["plugin"], "swedbank") 15 | 16 | def test_default_configuration(self) -> None: 17 | default_config = configuration.read(configuration.get_default_location()) 18 | config = configuration.read() 19 | self.assertEqual(config, default_config) 20 | 21 | def test_missing_configuration(self) -> None: 22 | config = configuration.read("missing.ini") 23 | self.assertIsNone(config) 24 | 25 | def test_missing_section(self) -> None: 26 | here = os.path.dirname(__file__) 27 | cfname = os.path.join(here, "samples", "config.ini") 28 | config = configuration.read(cfname) 29 | with self.assertRaises(Abort): 30 | configuration.get_settings(config, "kawabanga") 31 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_ofx.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | import xml.dom.minidom 3 | from decimal import Decimal 4 | 5 | from datetime import datetime, timezone, timedelta 6 | 7 | from ofxstatement.statement import Statement, StatementLine, BankAccount, Currency 8 | from ofxstatement import ofx 9 | 10 | SIMPLE_OFX = """ 11 | OFXHEADER:100 12 | DATA:OFXSGML 13 | VERSION:102 14 | SECURITY:NONE 15 | ENCODING:UNICODE 16 | CHARSET:NONE 17 | COMPRESSION:NONE 18 | OLDFILEUID:NONE 19 | NEWFILEUID:NONE 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | INFO 27 | 28 | 20120303000000 29 | ENG 30 | 31 | 32 | 33 | 34 | 0 35 | 36 | 0 37 | INFO 38 | 39 | 40 | LTL 41 | 42 | BID 43 | BRID 44 | ACCID 45 | CHECKING 46 | 47 | 48 | 49 | 50 | 51 | CHECK 52 | 20120212013025.200[-2.5] 53 | 15.40 54 | 1 55 | Sample 1 56 | 57 | 58 | CHECK 59 | 20120212104000 60 | 25.00 61 | 2 62 | 63 | SNORAS 64 | VNO 65 | LT1232 66 | CHECKING 67 | 68 | Sample 2 69 | 70 | USD 71 | 72 | 73 | EUR 74 | 3.4543 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | """ 87 | 88 | 89 | def prettyPrint(xmlstr: str) -> str: 90 | headers, sep, payload = xmlstr.partition("\r\n\r\n") 91 | dom = xml.dom.minidom.parseString(payload) 92 | pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace( 93 | '\r\n', "" 94 | ) 95 | return headers + sep + pretty_payload 96 | 97 | 98 | class OfxWriterTest(TestCase): 99 | def test_ofxWriter(self) -> None: 100 | # Create sample statement: 101 | statement = Statement( 102 | bank_id="BID", branch_id="BRID", account_id="ACCID", currency="LTL" 103 | ) 104 | statement.lines.append( 105 | StatementLine( 106 | "1", 107 | datetime( 108 | 2012, 2, 12, 1, 30, 25, 200950, timezone(timedelta(hours=-2.5)) 109 | ), 110 | "Sample 1", 111 | Decimal("15.4"), 112 | ) 113 | ) 114 | line = StatementLine( 115 | "2", datetime(2012, 2, 12, 10, 40, 0), "Sample 2", Decimal("25.0") 116 | ) 117 | line.payee = "" 118 | line.bank_account_to = BankAccount("SNORAS", "LT1232") 119 | line.bank_account_to.branch_id = "VNO" 120 | line.currency = Currency("USD") 121 | line.orig_currency = Currency("EUR", Decimal("3.4543")) 122 | statement.lines.append(line) 123 | 124 | # Create writer: 125 | writer = ofx.OfxWriter(statement) 126 | 127 | # Set the generation time so it is always predictable 128 | writer.genTime = datetime(2012, 3, 3, 0, 0, 0) 129 | 130 | assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip().replace("\n", "\r\n") 131 | 132 | def test_ofxWriter_pretty(self) -> None: 133 | # GIVEN 134 | statement = Statement("BID", "ACCID", "LTL") 135 | writer = ofx.OfxWriter(statement) 136 | writer.genTime = datetime(2021, 9, 3, 0, 0, 0) 137 | 138 | # WHEN 139 | xml = writer.toxml(pretty=True) 140 | 141 | # THEN 142 | expected = [ 143 | "OFXHEADER:100", 144 | "DATA:OFXSGML", 145 | "VERSION:102", 146 | "SECURITY:NONE", 147 | "ENCODING:UNICODE", 148 | "CHARSET:NONE", 149 | "COMPRESSION:NONE", 150 | "OLDFILEUID:NONE", 151 | "NEWFILEUID:NONE", 152 | "", 153 | "", 154 | " ", 155 | " ", 156 | " ", 157 | " 0", 158 | " INFO", 159 | " ", 160 | " 20210903000000", 161 | " ENG", 162 | " ", 163 | " ", 164 | "", 165 | "", 166 | ] 167 | 168 | assert xml.split("\r\n") == expected 169 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_ofx_invest.py: -------------------------------------------------------------------------------- 1 | from unittest import TestCase 2 | import xml.dom.minidom 3 | from decimal import Decimal 4 | 5 | from datetime import datetime 6 | 7 | from ofxstatement.statement import Statement, InvestStatementLine 8 | from ofxstatement import ofx 9 | 10 | SIMPLE_OFX = """ 11 | OFXHEADER:100 12 | DATA:OFXSGML 13 | VERSION:102 14 | SECURITY:NONE 15 | ENCODING:UNICODE 16 | CHARSET:NONE 17 | COMPRESSION:NONE 18 | OLDFILEUID:NONE 19 | NEWFILEUID:NONE 20 | 21 | 22 | 23 | 24 | 25 | 0 26 | INFO 27 | 28 | 20210501000000 29 | ENG 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | AAPL 38 | TICKER 39 | 40 | AAPL 41 | AAPL 42 | 43 | 44 | 45 | 46 | 47 | MSFT 48 | TICKER 49 | 50 | MSFT 51 | MSFT 52 | 53 | 54 | 55 | 56 | 57 | 58 | 0 59 | 60 | 0 61 | INFO 62 | 63 | 64 | 20210501000000 65 | LTL 66 | 67 | BROKERID 68 | ACCID 69 | 70 | 71 | 72 | 20210501 73 | 74 | BUY 75 | 76 | 77 | 3 78 | 20210101 79 | Sample 3 80 | 81 | 82 | AAPL 83 | TICKER 84 | 85 | OTHER 86 | OTHER 87 | 1.24000 88 | 138.28000 89 | 3.00000 90 | -416.08 91 | 92 | 93 | 94 | SELL 95 | 96 | 97 | 4 98 | 20210101 99 | Sample 4 100 | 101 | 102 | MSFT 103 | TICKER 104 | 105 | OTHER 106 | OTHER 107 | 0.28000 108 | 225.63000 109 | -5.00000 110 | 1127.87 111 | 112 | 113 | 114 | DIV 115 | 116 | 5 117 | 20210101 118 | Sample 5 119 | 120 | 121 | MSFT 122 | TICKER 123 | 124 | OTHER 125 | OTHER 126 | 0.50000 127 | 0.79 128 | 129 | 130 | 131 | INT 132 | 20210102 133 | 0.45 134 | 6 135 | Bank Interest 136 | 137 | OTHER 138 | 139 | 140 | 141 | 7 142 | 20210103 143 | Journaled Shares 144 | 145 | 146 | MSFT 147 | TICKER 148 | 149 | OTHER 150 | 225.63000 151 | 4.00000 152 | 153 | 154 | 155 | 8 156 | 20250101 157 | NRA Tax Adj 158 | 159 | 160 | AAPL 161 | TICKER 162 | 163 | OTHER 164 | OTHER 165 | -0.29 166 | 167 | 168 | 169 | 170 | 171 | 172 | """ 173 | 174 | 175 | def prettyPrint(xmlstr: str) -> str: 176 | headers, sep, payload = xmlstr.partition("\r\n\r\n") 177 | dom = xml.dom.minidom.parseString(payload) 178 | pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace( 179 | '\r\n', "" 180 | ) 181 | return headers + sep + pretty_payload 182 | 183 | 184 | class OfxInvestLinesWriterTest(TestCase): 185 | def test_ofxWriter(self) -> None: 186 | # Create sample statement: 187 | statement = Statement("BID", "ACCID", "LTL") 188 | statement.broker_id = "BROKERID" 189 | statement.end_date = datetime(2021, 5, 1) 190 | 191 | invest_line = InvestStatementLine( 192 | "3", 193 | datetime(2021, 1, 1), 194 | "Sample 3", 195 | "BUYSTOCK", 196 | "BUY", 197 | "AAPL", 198 | Decimal("-416.08"), 199 | ) 200 | invest_line.units = Decimal("3") 201 | invest_line.unit_price = Decimal("138.28") 202 | invest_line.fees = Decimal("1.24") 203 | invest_line.assert_valid() 204 | statement.invest_lines.append(invest_line) 205 | 206 | invest_line = InvestStatementLine( 207 | "4", 208 | datetime(2021, 1, 1), 209 | "Sample 4", 210 | "SELLSTOCK", 211 | "SELL", 212 | "MSFT", 213 | Decimal("1127.87"), 214 | ) 215 | invest_line.units = Decimal("-5") 216 | invest_line.unit_price = Decimal("225.63") 217 | invest_line.fees = Decimal("0.28") 218 | invest_line.assert_valid() 219 | statement.invest_lines.append(invest_line) 220 | 221 | invest_line = InvestStatementLine( 222 | "5", 223 | datetime(2021, 1, 1), 224 | "Sample 5", 225 | "INCOME", 226 | "DIV", 227 | "MSFT", 228 | Decimal("0.79"), 229 | ) 230 | invest_line.fees = Decimal("0.5") 231 | invest_line.assert_valid() 232 | statement.invest_lines.append(invest_line) 233 | 234 | invest_line = InvestStatementLine( 235 | "6", datetime(2021, 1, 2), "Bank Interest", "INVBANKTRAN", "INT" 236 | ) 237 | invest_line.amount = Decimal("0.45") 238 | invest_line.assert_valid() 239 | statement.invest_lines.append(invest_line) 240 | 241 | invest_line = InvestStatementLine( 242 | "7", datetime(2021, 1, 3), "Journaled Shares", "TRANSFER" 243 | ) 244 | invest_line.security_id = "MSFT" 245 | invest_line.units = Decimal("4") 246 | invest_line.unit_price = Decimal("225.63") 247 | invest_line.assert_valid() 248 | statement.invest_lines.append(invest_line) 249 | 250 | invest_line = InvestStatementLine( 251 | "8", 252 | datetime(2025, 1, 1), 253 | "NRA Tax Adj", 254 | "INVEXPENSE", 255 | None, 256 | "AAPL", 257 | Decimal("-0.29"), 258 | ) 259 | invest_line.assert_valid() 260 | statement.invest_lines.append(invest_line) 261 | 262 | # Create writer: 263 | writer = ofx.OfxWriter(statement) 264 | 265 | # Set the generation time so it is always predictable 266 | writer.genTime = datetime(2021, 5, 1, 0, 0, 0) 267 | 268 | assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip().replace("\n", "\r\n") 269 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_parser.py: -------------------------------------------------------------------------------- 1 | import io 2 | from textwrap import dedent 3 | from unittest import TestCase 4 | from decimal import Decimal 5 | 6 | from ofxstatement.parser import CsvStatementParser 7 | 8 | 9 | class CsvStatementParserTest(TestCase): 10 | def test_simple_csv_parser(self) -> None: 11 | # Test generic CsvStatementParser 12 | 13 | # Lets define some sample csv to parse and write it to file-like object 14 | csv = dedent( 15 | """ 16 | "2012-01-18","Microsoft","Windows XP",243.32,"1001" 17 | "2012-02-14","Google","Adwords",23.54,"1002" 18 | """ 19 | ) 20 | f = io.StringIO(csv) 21 | 22 | # Create and configure csv parser: 23 | parser = CsvStatementParser(f) 24 | parser.mappings = {"date": 0, "payee": 1, "memo": 2, "amount": 3, "id": 4} 25 | 26 | # And parse csv: 27 | statement = parser.parse() 28 | self.assertEqual(len(statement.lines), 2) 29 | self.assertEqual(statement.lines[0].amount, Decimal("243.32")) 30 | self.assertEqual(statement.lines[1].payee, "Google") 31 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_plugin.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest import mock 3 | 4 | import sys 5 | 6 | if sys.version_info < (3, 10): 7 | from importlib_metadata import EntryPoints 8 | else: 9 | from importlib.metadata import EntryPoints 10 | 11 | from ofxstatement import plugin 12 | 13 | 14 | class PluginTest(unittest.TestCase): 15 | def test_get_plugin(self) -> None: 16 | class SamplePlugin(plugin.Plugin): 17 | def get_parser(self): 18 | return mock.Mock() 19 | 20 | ep = mock.Mock() 21 | ep.load.return_value = SamplePlugin 22 | ep_patch = mock.patch( 23 | "ofxstatement.plugin.entry_points", return_value=EntryPoints([ep]) 24 | ) 25 | with ep_patch: 26 | p = plugin.get_plugin("sample", mock.Mock("UI"), mock.Mock("Settings")) 27 | self.assertIsInstance(p, SamplePlugin) 28 | 29 | def test_get_plugin_conflict(self) -> None: 30 | ep = mock.Mock() 31 | 32 | ep_patch = mock.patch( 33 | "ofxstatement.plugin.entry_points", return_value=EntryPoints([ep, ep]) 34 | ) 35 | with ep_patch: 36 | with self.assertRaises(plugin.PluginNameConflict): 37 | plugin.get_plugin("conflicting", mock.Mock("UI"), mock.Mock("Settings")) 38 | 39 | def test_get_plugin_not_found(self) -> None: 40 | with self.assertRaises(plugin.PluginNotRegistered): 41 | plugin.get_plugin("not_existing", mock.Mock("UI"), mock.Mock("Settings")) 42 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_statement.py: -------------------------------------------------------------------------------- 1 | from typing import Set 2 | import unittest 3 | from datetime import datetime 4 | from decimal import Decimal 5 | 6 | from ofxstatement import statement 7 | 8 | 9 | class StatementTests(unittest.TestCase): 10 | def test_generate_transaction_id_idempotent(self) -> None: 11 | # GIVEN 12 | stl = statement.StatementLine( 13 | "one", datetime(2020, 3, 25), memo="123", amount=Decimal("12.43") 14 | ) 15 | tid1 = statement.generate_transaction_id(stl) 16 | 17 | # WHEN 18 | # Subsequent calls with the same data generates exactly the same 19 | # transaction id 20 | tid2 = statement.generate_transaction_id(stl) 21 | 22 | # THEN 23 | self.assertEqual(tid1, tid2) 24 | 25 | def test_generate_transaction_id_identifying(self) -> None: 26 | # GIVEN 27 | stl = statement.StatementLine( 28 | "one", datetime(2020, 3, 25), memo="123", amount=Decimal("12.43") 29 | ) 30 | tid1 = statement.generate_transaction_id(stl) 31 | 32 | # WHEN 33 | # Different data generates different transaction id 34 | stl.amount = Decimal("1.01") 35 | tid2 = statement.generate_transaction_id(stl) 36 | 37 | # THEN 38 | self.assertNotEqual(tid1, tid2) 39 | 40 | def test_generate_unique_transaction_id(self) -> None: 41 | # GIVEN 42 | stl = statement.StatementLine("one", datetime(2020, 3, 25)) 43 | txnids: Set[str] = set() 44 | 45 | # WHEN 46 | tid1 = statement.generate_unique_transaction_id(stl, txnids) 47 | tid2 = statement.generate_unique_transaction_id(stl, txnids) 48 | 49 | self.assertNotEqual(tid1, tid2) 50 | 51 | self.assertTrue(tid2.endswith("-1")) 52 | self.assertEqual(len(txnids), 2) 53 | 54 | def test_transfer_line_validation(self) -> None: 55 | line = statement.InvestStatementLine("id", datetime(2020, 3, 25)) 56 | line.trntype = "TRANSFER" 57 | line.security_id = "ABC" 58 | line.units = Decimal(2) 59 | line.assert_valid() 60 | with self.assertRaises(AssertionError): 61 | line.security_id = None 62 | line.assert_valid() 63 | line.security_id = "ABC" 64 | with self.assertRaises(AssertionError): 65 | line.units = None 66 | line.assert_valid() 67 | line.units = Decimal(2) 68 | with self.assertRaises(AssertionError): 69 | line.trntype_detailed = "DETAIL" 70 | line.assert_valid() 71 | 72 | def test_invbank_line_validation(self) -> None: 73 | line = statement.InvestStatementLine("id", datetime(2020, 3, 25)) 74 | line.trntype = "INVBANKTRAN" 75 | line.trntype_detailed = "INT" 76 | line.amount = Decimal(1) 77 | line.assert_valid() 78 | with self.assertRaises(AssertionError): 79 | line.amount = None 80 | line.assert_valid() 81 | line.amount = Decimal(1) 82 | with self.assertRaises(AssertionError): 83 | line.trntype_detailed = "BLAH" 84 | line.assert_valid() 85 | 86 | def test_income_line_validation(self) -> None: 87 | line = statement.InvestStatementLine("id", datetime(2020, 3, 25)) 88 | line.trntype = "INCOME" 89 | line.trntype_detailed = "INTEREST" 90 | line.amount = Decimal(1) 91 | line.security_id = "AAPL" 92 | line.assert_valid() 93 | with self.assertRaises(AssertionError): 94 | line.amount = None 95 | line.assert_valid() 96 | line.amount = Decimal(1) 97 | with self.assertRaises(AssertionError): 98 | line.trntype_detailed = "BLAH" 99 | line.assert_valid() 100 | line.trntype_detailed = "INTEREST" 101 | with self.assertRaises(AssertionError): 102 | line.security_id = None 103 | line.assert_valid() 104 | 105 | def test_buy_line_validation(self) -> None: 106 | line = statement.InvestStatementLine("id", datetime(2020, 3, 25)) 107 | line.trntype = "BUYSTOCK" 108 | line.trntype_detailed = "BUY" 109 | line.amount = Decimal(1) 110 | line.security_id = "AAPL" 111 | line.units = Decimal(3) 112 | line.unit_price = Decimal(1.1) 113 | line.assert_valid() 114 | 115 | with self.assertRaises(AssertionError): 116 | line.amount = None 117 | line.assert_valid() 118 | line.amount = Decimal(1) 119 | 120 | with self.assertRaises(AssertionError): 121 | line.trntype_detailed = "BLAH" 122 | line.assert_valid() 123 | line.trntype_detailed = "INTEREST" 124 | 125 | with self.assertRaises(AssertionError): 126 | line.security_id = None 127 | line.assert_valid() 128 | line.security_id = "AAPL" 129 | 130 | with self.assertRaises(AssertionError): 131 | line.units = None 132 | line.assert_valid() 133 | line.units = Decimal(3) 134 | 135 | with self.assertRaises(AssertionError): 136 | line.unit_price = None 137 | line.assert_valid() 138 | 139 | def test_invexpense_line_validation(self) -> None: 140 | line = statement.InvestStatementLine("id", datetime(2020, 3, 25)) 141 | line.trntype = "INVEXPENSE" 142 | line.amount = Decimal(1) 143 | line.security_id = "AAPL" 144 | line.assert_valid() 145 | with self.assertRaises(AssertionError): 146 | line.amount = None 147 | line.assert_valid() 148 | line.amount = Decimal(1) 149 | with self.assertRaises(AssertionError): 150 | line.trntype_detailed = "SOMETHING" 151 | line.assert_valid() 152 | line.trntype_detailed = None 153 | with self.assertRaises(AssertionError): 154 | line.security_id = None 155 | line.assert_valid() 156 | -------------------------------------------------------------------------------- /src/ofxstatement/tests/test_tool.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import unittest 4 | import tempfile 5 | import io 6 | import logging 7 | import logging.handlers 8 | import shutil 9 | from typing import Dict 10 | from unittest import mock 11 | 12 | from ofxstatement import tool, statement, configuration, parser, exceptions 13 | 14 | 15 | class ToolTests(unittest.TestCase): 16 | def test_convert_configured(self) -> None: 17 | inputfname = os.path.join(self.tmpdir, "input") 18 | outputfname = os.path.join(self.tmpdir, "output") 19 | args = mock.Mock(type="test", input=inputfname, output=outputfname) 20 | 21 | config = {"test": {"plugin": "sample"}} 22 | 23 | parser = mock.Mock() 24 | parser.parse.return_value = statement.Statement() 25 | 26 | sample_plugin = mock.Mock() 27 | sample_plugin.get_parser.return_value = parser 28 | 29 | configpatch = mock.patch("ofxstatement.configuration.read", return_value=config) 30 | 31 | pluginpatch = mock.patch( 32 | "ofxstatement.plugin.get_plugin", return_value=sample_plugin 33 | ) 34 | 35 | with configpatch, pluginpatch: 36 | ret = tool.convert(args) 37 | 38 | self.assertEqual(ret, 0) 39 | self.assertEqual( 40 | self.log.getvalue().splitlines(), 41 | ["INFO: Conversion completed: (0 lines, 0 invest-lines) %s" % inputfname], 42 | ) 43 | 44 | def test_convert_noconf(self) -> None: 45 | inputfname = os.path.join(self.tmpdir, "input") 46 | outputfname = os.path.join(self.tmpdir, "output") 47 | args = mock.Mock(type="test", input=inputfname, output=outputfname) 48 | 49 | parser = mock.Mock() 50 | parser.parse.return_value = statement.Statement() 51 | 52 | sample_plugin = mock.Mock() 53 | sample_plugin.get_parser.return_value = parser 54 | 55 | noconfigpatch = mock.patch("ofxstatement.configuration.read", return_value=None) 56 | pluginpatch = mock.patch( 57 | "ofxstatement.plugin.get_plugin", return_value=sample_plugin 58 | ) 59 | 60 | with noconfigpatch, pluginpatch: 61 | ret = tool.convert(args) 62 | 63 | self.assertEqual(ret, 0) 64 | 65 | self.assertEqual( 66 | self.log.getvalue().splitlines(), 67 | ["INFO: Conversion completed: (0 lines, 0 invest-lines) %s" % inputfname], 68 | ) 69 | 70 | def test_convert_parseerror(self) -> None: 71 | inputfname = os.path.join(self.tmpdir, "input") 72 | outputfname = os.path.join(self.tmpdir, "output") 73 | 74 | class FailingParser(parser.StatementParser): 75 | def parse(self): 76 | raise exceptions.ParseError(23, "Catastrophic error") 77 | 78 | sample_plugin = mock.Mock() 79 | sample_plugin.get_parser.return_value = FailingParser() 80 | 81 | noconfigpatch = mock.patch("ofxstatement.configuration.read", return_value=None) 82 | 83 | pluginpatch = mock.patch( 84 | "ofxstatement.plugin.get_plugin", return_value=sample_plugin 85 | ) 86 | 87 | with noconfigpatch, pluginpatch: 88 | ret = tool.run(["convert", "-t test", inputfname, outputfname]) 89 | 90 | self.assertEqual(ret, 2) 91 | self.assertEqual( 92 | self.log.getvalue().splitlines(), 93 | ["ERROR: Parse error on line 23: Catastrophic error"], 94 | ) 95 | 96 | def test_list_plugins_plugins(self) -> None: 97 | pl1 = mock.Mock(__doc__="Plugin one") 98 | pl2 = mock.Mock() 99 | plugins = [("pl1", pl1), ("pl2", pl2)] 100 | 101 | pluginpatch = mock.patch( 102 | "ofxstatement.plugin.list_plugins", return_value=plugins 103 | ) 104 | outpatch = mock.patch("sys.stdout", self.log) 105 | 106 | with pluginpatch, outpatch: 107 | tool.run(["list-plugins"]) 108 | 109 | self.assertEqual( 110 | self.log.getvalue().splitlines(), 111 | [ 112 | "The following plugins are available: ", 113 | "", 114 | " pl1 Plugin one", 115 | " pl2 ", 116 | ], 117 | ) 118 | 119 | def test_list_plugins_noplugins(self) -> None: 120 | pluginpatch = mock.patch("ofxstatement.plugin.list_plugins", return_value=[]) 121 | outpatch = mock.patch("sys.stdout", self.log) 122 | with pluginpatch, outpatch: 123 | tool.run(["list-plugins"]) 124 | 125 | self.assertEqual( 126 | self.log.getvalue().splitlines(), 127 | [ 128 | "No plugins available. Install plugin eggs or create your own.", 129 | "See https://github.com/kedder/ofxstatement for more info.", 130 | ], 131 | ) 132 | 133 | def test_editconfig_noconfdir(self) -> None: 134 | # config directory does not exist yet 135 | confdir = os.path.join(self.tmpdir, "config") 136 | confpath = os.path.join(confdir, "config.ini") 137 | locpatch = mock.patch.object( 138 | configuration, "get_default_location", return_value=confpath 139 | ) 140 | 141 | call = mock.Mock() 142 | makedirs = mock.Mock() 143 | mkdirspatch = mock.patch("os.makedirs", makedirs) 144 | subprocesspatch = mock.patch("subprocess.call", call) 145 | envpatch = mock.patch("os.environ", {"EDITOR": "notepad.exe"}) 146 | 147 | with locpatch, envpatch, mkdirspatch, subprocesspatch: 148 | tool.run(["edit-config"]) 149 | 150 | makedirs.assert_called_once_with(confdir, mode=0o700) 151 | call.assert_called_once_with(["notepad.exe", confpath]) 152 | 153 | def test_editconfig_existing(self) -> None: 154 | # config directory already exists 155 | confpath = os.path.join(self.tmpdir, "config.ini") 156 | locpatch = mock.patch.object( 157 | configuration, "get_default_location", return_value=confpath 158 | ) 159 | makedirs = mock.Mock() 160 | mkdirspatch = mock.patch("os.makedirs", makedirs) 161 | 162 | call = mock.Mock() 163 | subprocesspatch = mock.patch("subprocess.call", call) 164 | 165 | env: Dict[str, str] = {} 166 | envpatch = mock.patch("os.environ", env) 167 | 168 | with locpatch, envpatch, mkdirspatch, subprocesspatch: 169 | tool.run(["edit-config"]) 170 | 171 | self.assertEqual(makedirs.mock_calls, []) 172 | editors = {"Linux": "vim", "Darwin": "vi", "Windows": "notepad"} 173 | call.assert_called_once_with([editors[platform.system()], confpath]) 174 | 175 | def setUp(self) -> None: 176 | self.tmpdir = tempfile.mkdtemp(suffix="ofxstatement") 177 | self.setUpLogging() 178 | 179 | def tearDown(self) -> None: 180 | self.tearDownLogging() 181 | shutil.rmtree(self.tmpdir) 182 | 183 | def setUpLogging(self) -> None: 184 | self.log = io.StringIO() 185 | fmt = logging.Formatter("%(levelname)s: %(message)s") 186 | self.loghandler = logging.StreamHandler(self.log) 187 | self.loghandler.setFormatter(fmt) 188 | logging.root.addHandler(self.loghandler) 189 | logging.root.setLevel(logging.INFO) 190 | 191 | def tearDownLogging(self) -> None: 192 | logging.root.removeHandler(self.loghandler) 193 | -------------------------------------------------------------------------------- /src/ofxstatement/tool.py: -------------------------------------------------------------------------------- 1 | """Command line tool for converting statements to OFX format""" 2 | 3 | import os 4 | import argparse 5 | import shlex 6 | import subprocess 7 | import logging 8 | import platform 9 | import sys 10 | import contextlib 11 | 12 | if sys.version_info < (3, 10): 13 | from importlib_metadata import version 14 | else: 15 | from importlib.metadata import version 16 | 17 | 18 | from ofxstatement import ui, configuration, plugin, ofx, exceptions 19 | from typing import Optional, TextIO, Generator 20 | 21 | 22 | log = logging.getLogger(__name__) 23 | 24 | 25 | @contextlib.contextmanager 26 | def smart_open( 27 | filename: Optional[str] = None, encoding: Optional[str] = None 28 | ) -> Generator[TextIO, None, None]: 29 | """See https://stackoverflow.com/questions/17602878/how-to-handle-both-with-open-and-sys-stdout-nicely""" # noqa 30 | fh: TextIO 31 | 32 | if filename and filename != "-": 33 | # encoding is required in cases when OS defaults to encoding which 34 | # doesn't support unicode characters, for example Windows defaults to 35 | # 'cp1252' 36 | fh = open(filename, "w", encoding=encoding) 37 | else: 38 | fh = sys.stdout 39 | 40 | try: 41 | yield fh 42 | finally: 43 | if fh is not sys.stdout: 44 | fh.close() 45 | 46 | 47 | def get_version() -> str: 48 | return version("ofxstatement") 49 | 50 | 51 | def configure_logging(args: argparse.Namespace) -> None: 52 | format = "%(levelname)s: %(message)s" 53 | arg_level = logging.DEBUG if args.debug else logging.INFO 54 | logging.basicConfig(format=format, level=arg_level) 55 | 56 | 57 | def make_args_parser() -> argparse.ArgumentParser: 58 | parser = argparse.ArgumentParser( 59 | description="Tool to convert proprietary bank statement " + "to OFX format." 60 | ) 61 | parser.add_argument( 62 | "--version", 63 | action="version", 64 | version="%%(prog)s %s" % get_version(), 65 | help="show current version", 66 | ) 67 | parser.add_argument( 68 | "-d", 69 | "--debug", 70 | action="store_true", 71 | default=False, 72 | help="show debugging information", 73 | ) 74 | 75 | subparsers = parser.add_subparsers(title="action") 76 | 77 | # convert 78 | parser_convert = subparsers.add_parser("convert", help="convert to OFX") 79 | 80 | parser_convert.add_argument( 81 | "-c", 82 | "--config", 83 | metavar="myconfig.ini", 84 | default=None, 85 | help="custom config file to use", 86 | ) 87 | parser_convert.add_argument( 88 | "-t", 89 | "--type", 90 | required=True, 91 | help=( 92 | "input file type. This is a section in " 93 | "the config file or plugin name if you " 94 | "have no config file." 95 | ), 96 | ) 97 | parser_convert.add_argument( 98 | "-p", 99 | "--pretty", 100 | action="store_true", 101 | default=False, 102 | help="produce pretty xml with nested tags properly indented.", 103 | ) 104 | parser_convert.add_argument("input", help="input file to process") 105 | parser_convert.add_argument( 106 | "output", 107 | help=( 108 | "output (OFX) file to produce where a minus (-) " 109 | "means writing to standard output instead" 110 | ), 111 | ) 112 | parser_convert.set_defaults(func=convert) 113 | 114 | # list-plugins 115 | parser_list = subparsers.add_parser("list-plugins", help="list available plugins") 116 | parser_list.set_defaults(func=list_plugins) 117 | 118 | # edit-config 119 | parser_edit = subparsers.add_parser( 120 | "edit-config", help=("open configuration file in " "default editor") 121 | ) 122 | parser_edit.set_defaults(func=edit_config) 123 | 124 | return parser 125 | 126 | 127 | def list_plugins(args: argparse.Namespace) -> None: 128 | available_plugins = plugin.list_plugins() 129 | if not available_plugins: 130 | print("No plugins available. Install plugin eggs or create your own.") 131 | print("See https://github.com/kedder/ofxstatement for more info.") 132 | 133 | else: 134 | print("The following plugins are available: ") 135 | print("") 136 | for name, plclass in available_plugins: 137 | if plclass.__doc__: 138 | title = plclass.__doc__.splitlines()[0] 139 | else: 140 | title = "" 141 | print(" %-16s %s" % (name, title)) 142 | 143 | 144 | def edit_config(args: argparse.Namespace) -> None: 145 | editors = {"Linux": "vim", "Darwin": "vi", "Windows": "notepad"} 146 | editor = os.environ.get("EDITOR", editors[platform.system()]) 147 | configfname = configuration.get_default_location() 148 | configdir = os.path.dirname(configfname) 149 | if not os.path.exists(configdir): 150 | log.info("Creating confugration directory: %s" % configdir) 151 | os.makedirs(configdir, mode=0o700) 152 | log.info("Running editor: %s %s" % (editor, configfname)) 153 | subprocess.call(shlex.split(editor, posix=(os.name == "posix")) + [configfname]) 154 | 155 | 156 | def convert(args: argparse.Namespace) -> int: 157 | appui = ui.UI() 158 | config = configuration.read(args.config) 159 | 160 | if config is None: 161 | # No configuration mode 162 | settings = {} 163 | pname = args.type 164 | else: 165 | # Configuration is loaded 166 | if args.type not in config: 167 | log.error("No section '%s' in config file." % args.type) 168 | log.error( 169 | "Edit configuration using ofxstatement edit-config and " 170 | "add section [%s]." % args.type 171 | ) 172 | return 1 # error 173 | 174 | settings = dict(config[args.type]) 175 | 176 | pname = settings.get("plugin", None) 177 | if not pname: 178 | log.error("Specify 'plugin' setting for section [%s]" % args.type) 179 | return 1 # error 180 | 181 | # pick and configure plugin 182 | try: 183 | p = plugin.get_plugin(pname, appui, settings) 184 | except plugin.PluginNotRegistered: 185 | log.error("No plugin named '%s' is found" % pname) 186 | return 1 # error 187 | 188 | # process the input and produce output 189 | parser = p.get_parser(args.input) 190 | try: 191 | statement = parser.parse() 192 | except exceptions.ParseError as e: 193 | log.error("Parse error on line %s: %s" % (e.lineno, e.message)) 194 | return 2 # parse error 195 | 196 | # Validate the statement 197 | try: 198 | statement.assert_valid() 199 | except exceptions.ValidationError as e: 200 | log.error("Statement validation error: %s" % (e.message)) 201 | return 2 # Validation error 202 | 203 | encoding = settings.get("encoding", "utf-8") 204 | with smart_open(args.output, encoding) as out: 205 | writer = ofx.OfxWriter(statement) 206 | out.write(writer.toxml(pretty=args.pretty, encoding=encoding)) 207 | 208 | n_lines = len(statement.lines) 209 | n_invest_lines = len(statement.invest_lines) 210 | log.info( 211 | "Conversion completed: (%d line%s, %d invest-line%s) %s" 212 | % ( 213 | n_lines, 214 | "s" if n_lines != 1 else "", 215 | n_invest_lines, 216 | "s" if n_invest_lines != 1 else "", 217 | args.input, 218 | ) 219 | ) 220 | return 0 # success 221 | 222 | 223 | def run(argv=None) -> int: 224 | parser = make_args_parser() 225 | args = parser.parse_args(argv) 226 | configure_logging(args) 227 | 228 | if not hasattr(args, "func"): 229 | parser.print_usage() 230 | parser.exit(1) 231 | 232 | return args.func(args) 233 | -------------------------------------------------------------------------------- /src/ofxstatement/ui.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | log = logging.getLogger(__name__) 4 | 5 | 6 | class UI: 7 | def status(self, message: str) -> None: 8 | log.info(message) 9 | 10 | def warning(self, message: str) -> None: 11 | log.warn(message) 12 | 13 | def error(self, message: str) -> None: 14 | log.error(message) 15 | --------------------------------------------------------------------------------