How to pass account to bean-file for archive folder definition?

187 views
Skip to first unread message

tbra...@gmail.com

unread,
Nov 10, 2021, 2:44:46 PM11/10/21
to Beancount
Hi,
I've previously relied very heavily on red's importers for my import and filing needs. They worked great up to the point when my Amex switched over from ofx to csv's -- the only options for statement/transaction downloads are excel, csv, and pdf.

I think I have a working importer for the new Amex csv's, but when I attempt to archive via bean-file, I receive the error:
ERROR:root:No account provided by importers: <<object.class of my importer>>

I think I'm missing a "return account" statement or similar but can't quite figure it out from the docs or red's other importers. I'm sure it's there but can't identify it.

Thanks for reading (and I hope answering),
Tim

tbra...@gmail.com

unread,
Nov 10, 2021, 2:57:23 PM11/10/21
to Beancount
Additional information: Here is my __init__

class AmexCCImporter(importer.ImporterProtocol):
    def __init__(self, account, lastfour):
        self.account = account
        self.lastfour = lastfour

The account does come through in the transaction narrative that is generated. However, it's not picked up by the file.py routine.

redst...@gmail.com

unread,
Nov 11, 2021, 2:03:42 AM11/11/21
to Beancount
Hello Tim,
That method is in beancount_reds_importers/libreader/reader.py, see here. If you imported the class correctly, that error should not occur:

class AmexCCImporter(banking.Importer, csvreader.Importer):
   def custom_init(self):
     # blah blah: Look at discover/__init__.py and replace ofxreader with csvreader.

Let me know if that worked.
But the more interesting answer to your question is: have you setup direct downloads (vs logging in via a browser)? If so, you'll get ofx from Amex, all from the command line that you can stick into a script. I checked my Amex two minutes ago, works fine and dandy:

ofxget stmt --nokeyring -u yourusername --password $(pass beancount/amex_card) amex -c 'CODECODE|last5' > ~/Downloads/amex_card.ofx

There's a one-time step to get your unique CODECODE, and I forget how it's done, but it's a pretty simple, single step IIRC, using ofxget. Post here if you're unable to get your code, and I'll try to dig up what I did.

RedS.

tbra...@gmail.com

unread,
Nov 12, 2021, 11:12:43 AM11/12/21
to Beancount
Thank you for your help, RedS

As a first step. I tried to modify copy your Disvcover --as well as the exisiting Amex -- importer, switing the ofxreader with csvreader. I also kept all of my mapping declarations going from csv "fields" to beancount narrative fields.
I wasn't able to get that to work quite right. I did finally bring over
    def file_account(self, _):
        return self.config['main_account']
...and it finally worked. However, I then get an error from bean-file:
unexpected error: 'AmexCCImporter' object has no attribute 'file_read_done'

This error is captured and the csv file is moved to the right place. The error might have been a bigger problem if I hadn't already "ingested" the file into my beancount ledger.

But just to dig in a little further...
file_read_done is defined in ...reds_importers.libreader.csvreader. So, I don't know why the stack is trying to retrieve this value from 'AmexCCImporter'.


I am working on the ofxget implementation next - will post results when I have them. If successful, it will sort of nullify this other effort, but I did learn something!

P.S. I don't know what's going on with the Times/Serif font in the middle of this post. I couldn't change that back to the normal Sans Serif text.

tbra...@gmail.com

unread,
Nov 12, 2021, 12:34:04 PM11/12/21
to Beancount
Looks like ofxget is a no-go too. One peculiarity that I have with this Amex account is that it is a company credit card - one that I am responsible to pay prior to being reimbursed by my employer. For this reason, and for help in creating my expense report, I like to track it with my personal accounts. Being a corporate card, it doesn't go through the normal American Express site. I log on to something called netservice - which has moved to "centresuite". I think this has something to do with integration into SAP for corporate accounting. Anyway, my credentials for the netservice site don't work with the amex ofxhome definition, and I think the whole API process might be different with the netservice site.

This might be too far "in the weeds" for this group and the main mission of Beancount. However, I'll try to pursue it a little further to see if there's an OFX server available for this account and try to continue on the ofx path. It is much cleaner than csv which in turn is easier than pdf extraction. Someone noted in another thread that ofx is being retired in many places. I hope that's not true!

redst...@gmail.com

unread,
Nov 13, 2021, 2:33:30 PM11/13/21
to Beancount
Ah yes, corporate accounts can be a hit or miss for ofx.

reds-importers is designed to work well with csvs as an alternative to ofx. You should be able to get a csv importer reliably working in a few minutes. Of course, csvs have to be downloaded manually. And you may not have the benefit of balance assertions if your csv does not contain it (most typically don't).

redst...@gmail.com

unread,
Nov 13, 2021, 2:56:20 PM11/13/21
to Beancount
Two things:
1. You shouldn't have to define file_account(). How have you configured your importer? (i.e., the config file that you pass to bean-file)?

2. 'file_read_done' issue might be a bug. Can you please file a bug at https://github.com/redstreet/beancount_reds_importers ?
With the versions of beancount, beangulp (if you're using that), and reds-importers you're using ('pip freeze' should tell you).

Fix might be to add 'self.initialize_reader(file)' at the beginning of this method, but I want to figure out what caused this (perhaps an upstream change).

tbra...@gmail.com

unread,
Nov 29, 2021, 11:59:13 AM11/29/21
to Beancount
I'm sorry - I dropped the ball on this as the credit card in question is moving to Mastercard in January, and I thought I would wait until then to finalize. I don't think I will do a fresh attempt using the reds importers csvreader and then file any required issues. What I ended up doing, which contradicts the "5 minute ledger update" framework but worked is writing an importer that includes custom csv parsing that only applies to the Amex account. I wasn't able to get far with smart importer on this one either.

For the sake of making sure bugs are captured though, I will document the "stock" handling of this situation using the reds importers package.

Thanks again for redstreet and martin and other major contributors to the program and this community!
Reply all
Reply to author
Forward
0 new messages