egh / ledger-autosync

Synchronize your ledger-cli files with your bank.
GNU General Public License v3.0
273 stars 42 forks source link

Intelligent append? #30

Closed paxperscientiam closed 7 years ago

paxperscientiam commented 7 years ago

Hello,

So, ledger-autosync can crosscheck journal files with OFX/QFX to prevent generating output for transactions that already exist in said journal files.

Can not this be further leveraged to add transactions to an existent journal file?

Currently, one can do something like this:

ledger-autosync 2015.06.01—2017.06.04_c.QFX >> c/tsac.journal

The problem with this is that there is no accounting for whether or not the transactions written into this journal file are already present. Hence, it would be awesome or there were some option to intelligently append transactions.

Thanks. Let me know if that's unclear.

egh commented 7 years ago

You can do the following:

ledger-autosync -l c/tsac.journal 2015.06.01—2017.06.04_c.QFX >> c/tsac.journal

At least, that works for me.

egh commented 7 years ago

Does that work for you?

paxperscientiam commented 7 years ago

Short answer: yes.

Long answer: So, it has since become clear to me that "includes" are parsed by ledger-autosync as well. This, renders the issue of adding the same transactions multiple times moot. This, though, assumes that stdout is redirected to a file that is already included -- include path/to/child.ledger -- in the main ledger file.

For example:

That is really cool.

Maybe I'm overly worried about the end-user, but my concern is that ">>" is one typo away from ">". Some may have noclobber set, but I'm not sure how common that is.

At any rate, maybe this is more of a fringe concern than I had originally thought

egh commented 7 years ago

@paxperscientiam I'm actually a little confused about what you want to do.

ledger-autosync relies on ledger/hledger to find the old transactions. It basically just runs ledger with the right search query to find the old transactions. So it will process any includes, etc. that ledger will.

If you are running ledger-autosync against a local OFX or CSV file, ledger-autosync does assume that transactions are not repeated within the file. If they are, or course you will get duplicate transactions, but ledger-autosync should only generate 1 output transactions per input transaction.

If you are using the OFX protocol, ledger-autosync will request transactions for period of time from your bank. It will request larger and larger time increments until it sees transactions that it has seen before. It then processes all the transactions within that time period, outputting only the transactions that are not present in your ledger files already.

I use ledger-autosync by outputting to a temp file and then copying the entries over to my ledger files. This works perfectly for me.

paxperscientiam commented 7 years ago

Hi @egh,

I think I was operating on misunderstandings; I take full responsibility for the confusion :)

Thank you for clarifying how ledger and ledger-autosync interface. It helps a lot.

See you at the next issue!

egh commented 7 years ago

Great, thank you!