# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['ledger_importer']

package_data = \
{'': ['*']}

install_requires = \
['typer>=0.4.1,<0.5.0']

entry_points = \
{'console_scripts': ['ledger_importer = ledger_importer.__main__:app']}

setup_kwargs = {
    'name': 'ledger-importer',
    'version': '0.5.0',
    'description': 'ledger_importer is a csv-to-ledger importer that can be configured in Python.',
    'long_description': '# ledger_importer [![CircleCI](https://circleci.com/gh/volnt/ledger_importer.svg?style=shield&circle-token=afb73aed03518c8658de39f5d61ec3bfdf50d57c)](https://app.circleci.com/settings/project/github/volnt/ledger_importer)\n\nledger_importer is a csv-to-[ledger](https://www.ledger-cli.org/3.0/doc/ledger3.html) importer that can be configured in Python.\n\nThe key features are:\n\n* **Customization**: Designed to fit your specific needs perfectly.\n* **Auto-completion**: The confirmation step is auto-completed.\n* **Integration**: Easy to integrate with your pipeline.\n\nledger_importer main selling point is that if you know Python, you can write complex rules to match & parse accounts / target_accounts. All other tools try to be smart about the target_account matching part but offer very little customization (regex matching is the best I\'ve seen).\n\nAnother cool feature is that if you have several bank accounts, you can concatenate their csv exports and ledger_importer will de-duplicate transactions between them. The de-duplication rule can be customized to your needs.\n\n## Installation\n\n```sh\n$ pip install ledger-importer\n```\n\n## Quickstart\n\n1. Generate a new config file:\n\n```sh\npython -m ledger_importer init > my_importer.py\n```\n\n2. /Optional/: update the configuration for your needs (see the [Configure section](#Configure))\n\n3. Import your bank statement\n\n```sh\npython -m ledger_importer import --statement-path statement.csv --config-path my_importer.py::LedgerImporterConfig\n```\n\nNote: the ledger transactions are written to stdout. Redirect stdout to your ledger journal to write them there instead (add ` >> journal.ledger` at the end of the previous command).\n\n## Configure\n\n`ledger_importer` is configured in Python. You can give your configuration to the ledger_importer CLI using a string ressembling [pytest node ids](https://docs.pytest.org/en/latest/how-to/usage.html#nodeids). For example: `ledger_importer import --statement-path statement.csv --config-path ~/ledger/my_config.py::LedgerConfig`.\n\nA Config instance can be created by creating a new class that inherits `ledger_importer.Config`. This new class must implement the following methods:\n\n* `parse_date(self, fields: tuple) -> datetime.datetime`\n* `parse_payee(self, fields: tuple) -> str`\n* `parse_postings(self, fields: tuple) -> list[Posting]`\n\nThe argument `fields: tuple` will be the csv row, with each column as an element of the tuple.\n\nExample configuration file:\n\n```py\n#!/usr/bin/env python\nfrom __future__ import annotations\n\nimport datetime\nimport re\nfrom decimal import Decimal\n\nfrom ledger_importer import Config, Posting, Amount\n\n# Custom ledger importer configuration\nclass LedgerImporterConfig(Config):\n    # Define the number of lines that needs to be skipped at the beginning of the file.\n    # This is usefull if the csv has a line with the column names for example.\n    skip_lines: int = 1\n\n    # Define the csv delimiter\n    csv_delimiter: str = ";"\n\n    # The argument `fields` given in all parse_* methods contains a whole csv row in a tuple\n    # Each element of the tuple is a string representation of the column\n\n    def parse_date(self, fields: tuple) -> datetime.datetime:\n        return datetime.datetime.strptime(fields[0], "%m-%d-%Y")\n\n    def parse_payee(self, fields: tuple) -> str:\n        return fields[2]\n\n    def parse_postings(self, fields: tuple) -> list[Posting]:\n        amount = Amount(quantity=Decimal(re.sub("[€ ]", "", fields[3]).replace(",", ".")), commodity="€")\n        if amount > 0:\n            account = "Income"\n        else:\n            account = "Expenses"\n\n        posting = Posting(account="Assets:Checking", amount=amount)\n\n        # A Transaction should be at least 2 postings that have reversed amounts\n        return [posting, Posting(account=account, amount=amount.reverse())]\n```\n\n## Run\n\nTo run leger_importer:\n\n```sh\n$ python -m ledger_importer import --statement-path bank-statement.csv --journal-path journal.ledger --config-path my_importer.py::LedgerImporterConfig\n\n|        Account         |    Date    |  Amount  |        Payee        |\n| Assets:Account:Florent | 2021/07/29 | 1234.56€ | VIR LOLE FOOB A.R.L |\n\nWhich account provided this income? ([Income:Salary]/[q]uit/[s]kip)\n\n\n|        Account         |    Date    |  Amount |            Payee             |\n| Assets:Account:Florent | 2021/08/02 | -11.77€ | CARD  27/07/21 SWILE XX*XXXX |\n\nTo which account did this money go? ([Expenses:Restaurant]/[q]uit/[s]kip)\n\n\n|        Account         |    Date    |   Amount  |                  Payee                  |\n| Assets:Account:Florent | 2021/08/03 |  -784.00€ | VIR Save some € Mr.      Florent        |\n\nTo which account did this money go? ([Expenses]/[q]uit/[s]kip)\nAssets:Savings\n\n\n|        Account         |    Date    |  Amount |             Payee             |\n| Assets:Account:Florent | 2021/08/03 | -58.63€ | CARD  08/03/21 PAYPAL XX*XXXX |\n\nTo which account did this money go? ([Expenses:Shopping]/[q]uit/[s]kip)\nq\n```\n\n## Usage\n\nRoot command:\n\n```sh\n$ python -m ledger_importer --help\nUsage: python -m ledger_importer [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --help                          Show this message and exit.\n\nCommands:\n  import  Import a bank statement.\n  init    Bootstrap a config file that can later be customized.\n```\n\nImport command imports bank statement and generates ledger transactions:\n\n```sh\n$ python -m ledger_importer import --help\nUsage: python -m ledger_importer import [OPTIONS]\n\n  Import a bank statement.\n\nOptions:\n  --statement-path PATH  Path to the bank statement to import.  [required]\n  --config-path TEXT     Python path to the configuration file.  [required]\n  --journal-path PATH    Path a ledger journal to write & learn accounts from.\n  --quiet / --no-quiet   Don\'t ask questions and guess all the accounts\n                         automatically.  [default: no-quiet]\n  --help                 Show this message and exit.\n```\n\nInit command bootstraps a new config file:\n\n```sh\n$ python -m ledger_importer init --help\nUsage: python -m ledger_importer init [OPTIONS]\n\n  Bootstrap a config file that can later be customized.\n\nOptions:\n  --help  Show this message and exit.\n\n```\n',
    'author': 'Florent Espanet',
    'author_email': 'florent.esp@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/volnt/ledger_importer',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.8,<4.0',
}


setup(**setup_kwargs)
