fxtlabs / beansoup

A companion to beancount, a command-line double-entry accounting tool
GNU General Public License v2.0
11 stars 2 forks source link

Need help to use the mixin alongwith beancount.ingest.importers.ofx #1

Open mbkamble opened 6 years ago

mbkamble commented 6 years ago

Hi. I am noob with Python class inheritance. I read about mixins and got a beginner level understanding. But I am having trouble integrating your mixin.FilterChain class with the ofx importert from beancount. Could you show me a sample config file to use with bean-extract to use the transactions.TransactionCompleter filter?

Thanks, Milind

fxt commented 6 years ago

Hi Milind,

here is my import configuration file (with some private info blanked out). I hope it can help,

fxt

!/usr/bin/env python3

"""Import configuration."""

from beancount import loader from beancount.ingest import extract from beancount.ingest.importers import ofx from beansoup import transactions from beansoup.importers import amex, filing, mixins, td

existingentries, , _ = loader.load_file('my.beancount')

Set up preferences for the transaction completion filter

min_score, max_age, interpolated = 0.5, None, False

class OfxImporter(mixins.FilterChain, ofx.Importer): pass

class TDImporter(mixins.FilterChain, td.Importer): pass

Setting this variable provides a list of importer instances.

CONFIG = [ TDImporter("Assets:CA:Banking:TD:BusinessChequing", "CAD", "td-biz-checking", first_day=1, filename_regexp="TD-service-plan-1-\d{4}.csv", filters=[transactions.TransactionCompleter( existing_entries, "Assets:CA:Banking:TD:BusinessChequing", min_score, max_age, interpolated)]), TDImporter("Liabilities:CA:CreditCards:TD:Visa", "CAD", "td-visa", first_day=12, filename_regexp="TD-(gold-select-)?visa-\d{4}.csv", filters=[transactions.TransactionCompleter( existing_entries, "Liabilities:CA:CreditCards:TD:Visa", min_score, max_age, interpolated)]), OfxImporter("1234567", "Assets:CA:Banking:TD:AllInclusive", "td-all-inclusive", filters=[transactions.TransactionCompleter( existing_entries, "Assets:CA:Banking:TD:AllInclusive", min_score, max_age, interpolated)]), filing.Importer("Assets:CA:Banking:TD:AllInclusive", "td-all-inclusive", first_day=1, filename_regexp='^TD_ALL-INCLUSIVE_BANKINGPLAN 1234567\w{3}\d{1,2}-(?P\w{3})(?P\d{1,2}) (?P\d{4}).pdf$'), OfxImporter("2345678", "Assets:CA:Banking:TD:Borderless", "td-borderless", filters=[transactions.TransactionCompleter( existing_entries, "Assets:CA:Banking:TD:Borderless", min_score, max_age, interpolated)]), filing.Importer("Assets:CA:Banking:TD:Borderless", "td-borderless", first_day=1, filenameregexp='^BORDERLESS PLAN2345678\w{3}\d{1,2}-(?P\w{3})(?P\d{1,2} )_(?P\d{4}).pdf$'), OfxImporter("3456789", "Liabilities:CA:CreditCards:TD:Visa", "td-visa", filters=[transactions.TransactionCompleter( existing_entries, "Liabilities:CA:CreditCards:TD:Visa", min_score, max_age, interpolated)]), filing.Importer("Liabilities:CA:CreditCards:TD:Visa", "td-visa", first_day=12, filename_regexp='^TD_FIRST_CLASS_TRAVEL_VISAINFINITE CARD3456789(?P\w{3})_(?P\d{1,2})-(?P\d{4}).pdf$'), ]

Override the header on extracted text (if desired).

extract.HEADER = ';; -- mode: org; mode: beancount; coding: utf-8; --\n'

On Tue, Jan 16, 2018 at 12:15 PM, Milind Kamble notifications@github.com wrote:

Hi. I am noob with Python class inheritance. I read about mixins and got a beginner level understanding. But I am having trouble integrating your mixin.FilterChain class with the ofx importert from beancount. Could you show me a sample config file to use with bean-extract to use the transactions.TransactionCompleter filter?

Thanks, Milind

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fxtlabs/beansoup/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AAt91jk4mdM5IppwZX-oMO7QZLgCrmTaks5tLNkqgaJpZM4RgH0Z .

mbkamble commented 6 years ago

Hi fxt. Sorry for such a huge delay in responding. I had no idea that you had responded promptly. Thanks for sharing a sample config file. It improves my understanding of python and the use of filterchain mixin in a big way.

Regards, Milind

mbkamble commented 6 years ago

Hi Filipp. I reopened this issue to discuss/mention that I find the filterchain concept very useful in the manner you have articulated as a transaction completer. Have you reached out to the beancount maintainer (Martin Blais) to include it in codebase? I have extended the usage mode of this concept to handle the case when bean-extract is run with the -f option. In this case the config file (listing the importers) does not have access to 'existing_entries'. I prefer it that way because I don't want to hardcode the load_file('myfile') in my config file by rather pass it as '-f' option to bean-extract. In that case the filter needs to be re-init-ed, which I modified to do so at the beginning of complete_entries() in case of TransactionCompleter filter object. Other kinds of filter objects can choose to ignore that parameter if it is irrelevant.

In summary, I do like the idea of providing a transaction completer in form of a filterchain element because extract(fromnewfile) should only do the extraction without having to consider existing_entries.

I can share my changes with you if you want to see/review them.

Regards, Milind