How to default to importing transactions as uncleared?

125 views
Skip to first unread message

trs...@tutanota.com

unread,
Aug 4, 2018, 6:07:51 PM8/4/18
to Beancount Mailing List
Digging through the source code for beancount / beancount / ingest / importer.py [1]I came across the following:

```
class ImporterProtocol:
    "Interface that all source importers need to comply with."

    # A flag to use on new transaction. Override this flag in derived classes if
    # you prefer to create your imported transactions with a different flag.
    FLAG = flags.FLAG_OKAY
```

But I am not sure where to change that? I have tried to plug it in to various places in myledger.config file to pass it to the generic CSV importer but I can't seem to get it to work. FWIW, I did also make sure to put the following further up in the file:

```
from beancount.core import flags
```

Sorry, but my Python skills are still such that I cannot get my brain around all the scope, class, etc. type stuff and you have a lot of things going through other things in the code that I just can't follow.

TRS-80

NOTE 1: (big ugly link) https://bitbucket.org/blais/beancount/src/f2e603bd3027f9bcca10f8856bee418bc41abcb3/beancount/ingest/importer.py?at=default&fileviewer=file-view-default
--
Securely sent with Tutanota. Claim your encrypted mailbox today!
https://tutanota.com

Martin Blais

unread,
Aug 4, 2018, 9:41:15 PM8/4/18
to Beancount
Override the 'FLAG' attribute on your importer class.
e.g. 

class MyImporter ...
  FLAG = 'M'

BTW if you write a new importer, you can just ignore this and insert the flag you like, inline.




--
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+...@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/LJ5yrcZ--3-0%40tutanota.com.
For more options, visit https://groups.google.com/d/optout.

trs...@tutanota.com

unread,
Aug 5, 2018, 12:10:48 PM8/5/18
to bean...@googlegroups.com
> BTW if you write a new importer, you can just ignore this and insert the flag you like, inline.

Yes, of course. But so far I have been able to get away with using the provided, generic CSV Importer, and passing whatever I need to it through myledger.config file. Including even the categorizer which I implemented in there (before the CONFIG section) and everything works a treat.

I guess what I should have stated was "is there any way to pass this through the config file, without having to modify the Importer?"

It seems to me that it would be fairly simple to add in another variable that could be passed in the config to the generic CSV (or other?) Importer(s). This would be more modular and generic. And anyone who didn't want to use it could just leave it out and it would still default to cleared like it does now.

Or am I missing something here?

Thinking more, I suppose all Importers would then need to implement this so called "little" change? Or?

I'm still level 1 Python babby, so this foe is still beyond me (for the time being)...

TRS-80

--
Securely sent with Tutanota. Claim your encrypted mailbox today!
https://tutanota.com

4. Aug 2018 21:41 by bl...@furius.ca:

Override the 'FLAG' attribute on your importer class.
e.g. 

class MyImporter ...
  FLAG = 'M'






Martin Blais

unread,
Aug 5, 2018, 1:30:32 PM8/5/18
to Beancount
On Sun, Aug 5, 2018 at 12:10 PM <trs...@tutanota.com> wrote:
> BTW if you write a new importer, you can just ignore this and insert the flag you like, inline.

Yes, of course. But so far I have been able to get away with using the provided, generic CSV Importer, and passing whatever I need to it through myledger.config file. Including even the categorizer which I implemented in there (before the CONFIG section) and everything works a treat.

Sorry I might have read too fast.
Doing too much stuff at the same time.
 

I guess what I should have stated was "is there any way to pass this through the config file, without having to modify the Importer?"

You can derive a class from it and override the attribute.


 

It seems to me that it would be fairly simple to add in another variable that could be passed in the config to the generic CSV (or other?) Importer(s). This would be more modular and generic. And anyone who didn't want to use it could just leave it out and it would still default to cleared like it does now.

It's possible.
 

trs...@tutanota.com

unread,
Aug 8, 2018, 7:35:53 AM8/8/18
to bean...@googlegroups.com
I ended up just putting:

csv.Importer.FLAG = '!'

in myledger.config, somewhere above the CONFIG = [ ... ] part. And it works.

Is that kosher though?

I remember reading a bunch of other things in (IIRC) flags.py? But maybe all those other variable names are not needed just to parse txns in the importer?

Your post about deriving a class got me to reading more yet again about classes, etc. in Python and I think I'm starting to get my head around it.


TRS-80
--
Securely sent with Tutanota. Claim your encrypted mailbox today!
https://tutanota.com

5. Aug 2018 17:30 by bl...@furius.ca:

Reply all
Reply to author
Forward
0 new messages