bean-extract is just a Python script so you can debug it like any other
script:
python -m pdb `which bean-extract` my_importer.py test.csv
or if you want to stop at an exception:
python -m pdb -c continue `which bean-extract` my_importer.py test.csv
On Saturday, January 21, 2023 at 12:46:46 PM UTC-5 Moritz wrote:
> Orrr. Figured it out and made the importer working:
> Turned out, the last line of the CSV contained the headers again. Deleting
> this line fixed it.
>
> The debug question remains open ;)
>
> Moritz schrieb am Samstag, 21. Januar 2023 um 18:32:05 UTC+1:
>
>> Hi,
>>
>> I've exported my Amazon transactions into a `CSV` file using the `Amazon
>> Order History Reporter` extension. The file looks like this:
>>
>> ```
>> order id,order date,quantity,description,price
>> 300-1000000-1000000,2022-10-26,1,"Foo","19.99"
>> 300-1000000-2000000,2022-11-18,1,"bar","39.95"
>> ```
>>
>> I came up with this config file:
>>
>> ```
>>
>> from beancount.ingest.importers.csv import Importer as CSVImporter, Col
>>
>> my_amazon_csv_importer = CSVImporter({
>> Col.DATE: 'order date',
>> Col.NARRATION1: 'description',
>> Col.AMOUNT: 'price'
>> },
>> 'Expenses:Amazon', # account
>> 'EUR', # currency
>> # regexps used by ImporterProtocol.identify() to
>> identify the correct file
>> #('order id,order date,quantity,description,price'
>>
>> #),
>> skip_lines=0
>> )
>>
>>
>> CONFIG = [my_amazon_csv_importer]
>> ```
>> to extract the transactions with:
>>
>> ```
>> bean-extract config_amazon_csv.py amazon_order_history_2022.csv
>> ```
>>
>> But this fails with:
>> ```
>> ERROR:root:Importer beancount.ingest.importers.csv.Importer:
>> "Expenses:Amazon".extract() raised an unexpected error: Unknown string
>> format: order date
>> Traceback (most recent call last):
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/beancount/ingest/extract.py",
>>
>> line 182, in extract
>> new_entries = extract_from_file(
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/beancount/ingest/extract.py",
>>
>> line 67, in extract_from_file
>> new_entries = importer.extract(file, **kwargs)
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/beancount/ingest/importers/csv.py",
>>
>> line 294, in extract
>> date = parse_date_liberally(date, self.dateutil_kwds)
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/beancount/utils/date_utils.py",
>>
>> line 45, in parse_date_liberally
>> return dateutil.parser.parse(string, **parse_kwargs_dict).date()
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/dateutil/parser/_parser.py",
>>
>> line 1368, in parse
>> return DEFAULTPARSER.parse(timestr, **kwargs)
>> File
>> "/home/user/beancount/.venv/lib/python3.10/site-packages/dateutil/parser/_parser.py",
>>
>> line 643, in parse
>> raise ParserError("Unknown string format: %s", timestr)
>> dateutil.parser._parser.ParserError: Unknown string format: order date
>> ;; -*- mode: beancount -*-
>> ```
>>
>> What annoys me the most here is, that I cannot find a way to just call
>> the `bean-extract config_amazon_csv.py amazon_order_history_2022.csv` part
>> just from the `config_amazon_csv.py` file or another python script.
>> That would make it easy to set a breakpoint in my editor to check what is
>> happening exactly.
>> As I'm quite new to python: what is the proper way of calling
>> bean-extract for debugging purposes?
>>
>> So any pointers highly appreciated to get my amazon transactions to
>> beancount format.
>>
>> Moritz
>>
>
--
You received this message because you are subscribed to the Google Groups
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beancount/964505a4-7314-440c-9880-6e17ad2d4415n%40googlegroups.com.