jbms / beancount-import

Web UI for semi-automatically importing external data into beancount
GNU General Public License v2.0
391 stars 100 forks source link

GenericImporter issue when using a Revolut importer that works in beancount #178

Closed kosli closed 1 year ago

kosli commented 1 year ago

I have installed beancount-import and tested it by using the run.py from examples/data/fresh I would like to use the Importer from https://tariochbctools.readthedocs.io/en/latest/importers.html#revolut (https://github.com/tarioch/beancounttools/blob/master/src/tariochbctools/importers/revolut/importer.py)

So i adapted my _config.py by adding the following lines:

from tariochbctools.importers.revolut.importer import Importer as revolutimp

my_revolut_importer = revolutimp(
                       "/Revolut-CHF.*\.csv",
                       "Assets:Revolut:CHF", # account
                       "CHF", # currency
                        )

CONFIG = [my_foobar_bank_importer, my_amex_cc_importer, my_revolut_importer]

and the run.py too:

from _config import my_foobar_bank_importer, my_amex_cc_importer, my_revolut_importer

        dict(
            module='beancount_import.source.generic_importer_source',
            importer=my_revolut_importer,
            account='Assets:Revolut:CHF',
            directory=os.path.join(data_dir, 'importers')
        ),

and I have added the Revolut-CHF-2022-11-16.csv file into importers.

When i run run.py i get the following output:

Listening at http://127.0.0.1:8101
Traceback (most recent call last):
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/webserver.py", line 514, in _handle_reconciler_loaded
    loaded_reconciler = loaded_future.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/thread_helpers.py", line 13, in wrapper
    f.set_result(fn(*args, **kwargs))
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/reconcile.py", line 396, in __init__
    all_source_results = self._prepare_sources()
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/reconcile.py", line 520, in _prepare_sources
    source.prepare(self.editor, source_results)
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/source/generic_importer_source.py", line 80, in prepare
    get_pending_and_invalid_entries(
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/source/description_based_source.py", line 106, in get_pending_and_invalid_entries
    results.add_pending_entry(make_import_result(raw_entry))
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/source/generic_importer_source.py", line 130, in _make_import_result
    date=imported_entry.date, info=get_info(imported_entry), entries=[imported_entry])
  File "/home/xxx/.local/lib/python3.10/site-packages/beancount_import/source/generic_importer_source.py", line 138, in get_info
    if raw_entry.meta["filename"].endswith(".beancount"):
KeyError: 'filename'
> /home/xxx/.local/lib/python3.10/site-packages/beancount_import/source/generic_importer_source.py(138)get_info()
-> if raw_entry.meta["filename"].endswith(".beancount"):

It looks to me like something with the filename recognition goes wrong, but I don't know how to debug or where to start looking for the error.

When I use the importer straight with bean-extract and the following config, it works fine.

#!/usr/bin/env python3
from tariochbctools.importers.revolut import importer as revolutimp

CONFIG = [
    revolutimp.Importer("/Revolut-CHF.*\.csv", "Assets:Revolut:CHF", "CHF"),
    ]

Thanks for a hint in the right direction.

Zburatorul commented 1 year ago

Start by adding a print(raw_entry) statement right above the line throwing the exception. Does it look reasonable?

kosli commented 1 year ago

Thanks @Zburatorul I think i found the issue. The revolut importer does not return the meta when a balance entry is being returned https://github.com/tarioch/beancounttools/blob/5ae47a5884395451966619475a95c24b8ca56d00/src/tariochbctools/importers/revolut/importer.py#L80 I will close the issue here and try to fix the importer.