#!/usr/bin/env python3
'''Configuration file for extracting MyBank data'''
import sysfrom os import path
# from beancount.ingest import extract# from beancount.ingest.importers import csv
# from .importers import mybankimport importers.mybank
sys.path.insert(0, path.join(path.dirname(__file__)))
# from beancount.plugins import auto_accounts
CONFIG = [importers.mybank.Importer('Assets:Currency:MyBank')]
#!/usr/bin/env python3
'''Configuration file for extracting MyBank data'''
from beancount.ingest import regressionfrom beancount.ingest.importers import csv
from beancount.plugins import auto_accounts
class Importer(csv.Importer):
config = {csv.Col.DATE: 'Posted Date', csv.Col.TXN_DATE: 'Transaction Date', csv.Col.NARRATION1: 'Description', csv.Col.NARRATION2: 'Payee', csv.Col.NARRATION3: 'Payee account', csv.Col.AMOUNT: 'Amount', csv.Col.BALANCE: 'Balance'}
def __init__(self, account): csv.Importer.__init__( self, self.config, account, 'Currency', ('Transacton Date,Posted Date,Description,Payee,' 'Payee account,Amount,Balance'), 1)
def get_description(self, row): payee, narration = super().get_description() narration = '{} ({})'.format(narration, row.category) return payee, narration
$ bean-identify test.config.py bank_history_sample.csv Traceback (most recent call last): File "/usr/bin/bean-identify", line 4, in <module> from beancount.ingest.identify import main; main() File "/usr/lib/python3.6/site-packages/beancount/ingest/identify.py", line 93, in main _, config, downloads_directories = scripts_utils.parse_arguments(parser) File "/usr/lib/python3.6/site-packages/beancount/ingest/scripts_utils.py", line 56, in parse_arguments mod = runpy.run_path(args.config) File "/usr/lib/python3.6/runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "/usr/lib/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "test.config.py", line 15, in <module> import importers.mybankModuleNotFoundError: No module named 'importers'
sys.path.insert(0, path.join(path.dirname(__file__)))
import importers.mybank
I think it is this, but I have not tried running your code:sys.path.insert(0, path.join(path.dirname(__file__)))is what adds the path to your importers package, to the system path. So theimport importers.mybankNeeds to be after it. It is admittedly not correct python style, as imports should always come first, but it is a workaround beancount uses to be able to read your custom code.Good luck.
Now to figure out why nothing happens when I run bean-extract
--
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 beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/32737949-89a6-4fb2-80ed-ba8189931e6e%40googlegroups.com.
On Sun, Apr 8, 2018 at 3:17 AM, viq <vic...@gmail.com> wrote:
On Sunday, April 8, 2018 at 1:55:42 AM UTC+2, Michael Droogleever wrote:I think it is this, but I have not tried running your code:sys.path.insert(0, path.join(path.dirname(__file__)))is what adds the path to your importers package, to the system path. So theimport importers.mybankNeeds to be after it. It is admittedly not correct python style, as imports should always come first, but it is a workaround beancount uses to be able to read your custom code.Good luck.Indeed, with that change it doesn't complain about imports now, thank you! Apparently the same can be achieved by setting PYTHONPATH.Yes.I think we talked about adding the importer file's location automatically to PYTHONPATH, here:Not done yetNow to figure out why nothing happens when I run bean-extractRun bean-identify first. If it doesn't list the file, it hasn't identified it as something the importer can extract from.It uses the regexps you provide to match against the contents of the CSV file.I see a typo in your code, which probably explains why it doesn't match it:Transacton Date
$ bean-identify test.config.py bank_history_sample.csv**** /home/viq/Work/Own/beancount/bank_history_sample.csv
$ bean-extract test.config.py bank_history_sample.csv;; -*- mode: beancount -*-**** /home/viq/Work/Own/beancount/bank_history_sample.csv
pylint: [no-member] Super of 'Importer' has no 'get_description' member [E1101] (E)
--
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 beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/163c3c90-1c68-4e46-bcfc-96351f2bd688%40googlegroups.com.
- bean-identity saw your file.- It didn't match any of the configured importers (there's no section printed underneath it, if it matches it would print the importer and deduced account name, date and to-be-renamed location)Something to do with your regexp, it probably still doesn't match the header of your file.
--
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 beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/f8b2a0cf-1357-4a4f-bf82-0ee2ce558ff2%40googlegroups.com.
--
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 beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/20180422194611.z32tlg24bxpf27xk%40hirauchi.