Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.latest.- with imports from stdin #2315

Open
Terrance opened this issue Jan 12, 2025 · 3 comments
Open

.latest.- with imports from stdin #2315

Terrance opened this issue Jan 12, 2025 · 3 comments
Labels

Comments

@Terrance
Copy link

Importing via stdin (i.e. hledger import ... csv:-) creates a .latest.- file with that run's latest date, which means any other piped imports are subjected to that minimum date. This was a bit of a surprise as I'd expect the latest date not to be tracked here.

I'm using stdin as a way to reformat a series of different CSV files (e.g. sed ... $f.csv | hledger import ... csv:-), and I'd expect in general the source of a stdin import to vary between runs, so to me it would make more sense to suppress the .latest.- file by default when piping import data in, or else to have an option to prevent its creation / ignore it when present.

The import command help text talks about manipulating the latest files when needed, so I guess there's an expectation here that I'd remove them myself each time -- it just feels a little counter-intuitive.

@simonmichael
Copy link
Owner

Detection of new transactions is import's key feature, so it's natural for it to always write a .latest file (except in --dry-run mode). I agree that makes import - not very useful; I recently wrote a note about that for the docs.

It sounds like you don't need import here; wouldn't hledger print -f- do ?

@Terrance
Copy link
Author

Yes, I think piping the output of print to a journal file would have been the better process here -- I was deleting and reimporting secondary journal files as I tested other parts of the scripting, so just printing and scanning through them in a pager would have probably been much easier.

I have now converted my existing finance spreadsheet into a set of journals I can maintain going forwards (I have been convinced PTA is the future!), but I'm probably still scratching the surface -- slowly working my way through more of the docs as I tinker 🙂

I suppose the latest file for stdin is only a problem if you have multiple pipelines that need partial importing, and at that point it might be better wrapping it in a script to create intermediate CSV files anyway.

@simonmichael
Copy link
Owner

simonmichael commented Jan 23, 2025

When reading, you can specify the rules file: hledger print -f csv:- --rules=foo.rules

A similar option could be provided for specifying the latest file: hledger import csv:- --latest=.latest.foo

I'm not sure it's needed, but it would be consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants