mirror of
https://github.com/simonmichael/hledger.git
synced 2024-10-06 10:57:30 +03:00
examples: onelinecsv
This commit is contained in:
parent
17c7600d4c
commit
112668f10c
33
examples/onelinecsv.hs
Executable file
33
examples/onelinecsv.hs
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env stack
|
||||
{- stack runghc
|
||||
--package hledger-lib
|
||||
--package text
|
||||
-}
|
||||
{- example of generating one CSV line per txn. assumes hledger-lib 1.0+ -}
|
||||
|
||||
import Control.Monad
|
||||
import qualified Data.Text as T
|
||||
import Data.List
|
||||
import Hledger
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
Right j <- readJournalFile Nothing Nothing False "examples/sample.journal"
|
||||
putStrLn $ intercalate ", " $ [
|
||||
"date"
|
||||
,"description"
|
||||
,"account1"
|
||||
,"amount1"
|
||||
,"account2"
|
||||
,"amount2"
|
||||
]
|
||||
forM_ (jtxns j) $ \t -> do
|
||||
let (p1:p2:_) = tpostings t
|
||||
putStrLn $ intercalate ", " $ map quoteIfNeeded [
|
||||
show $ tdate t
|
||||
,T.unpack $ tdescription t
|
||||
,T.unpack $ paccount p1
|
||||
,show $ pamount p1
|
||||
,T.unpack $ paccount p2
|
||||
,show $ pamount p2
|
||||
]
|
Loading…
Reference in New Issue
Block a user