0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ledger CLIAdvent Calendar 2022

Day 16

wslでledger その4

Last updated at Posted at 2023-02-10

概要

wsl(wsl2じゃない)でledgerやってみた。
練習問題やってみた。

練習問題

elixirでcsvをledgerに読み込める様に変換せよ。

サンプルコード

defmodule Main do
    def main() do
        csv = """
2021-11-30T00:00:00,交通・通信,11614,ネット・電話等
2021-12-01T00:00:00,雑費,4277,新聞
2021-12-03T00:00:00,交通・通信,520,電車
2021-12-31T00:00:00,交通・通信,10140,ネット・電話等
2022-01-27T00:00:00,食料,332,amazon
2022-01-06T00:00:00,食料,570,マクドナルド
2022-01-02T00:00:00,交際費,4320,テパ地下
"""
        Enum.map(String.split(csv, "\n"), fn l ->
			print(l)
		end)
	end
    def print(nil) do
        IO.puts "ok"
    end
    def print(l) do
		s = String.split(l, ",")
		j = String.replace(Enum.at(s, 0), "T00:00:00", "")
		j = String.replace(j, "-", "/")
        IO.puts "#{j}  #{Enum.at(s, 4)}\n    Expenses:#{Enum.at(s, 1)}  #{Enum.at(s, 2)} JPY\n    Assets:全財産"
    end
end

Main.main




実行結果

2021/11/30  
    Expenses:交通・通信  11614 JPY
    Assets:全財産
2021/12/01  
    Expenses:雑費  4277 JPY
    Assets:全財産
2021/12/03  
    Expenses:交通・通信  520 JPY
    Assets:全財産
2021/12/31  
    Expenses:交通・通信  10140 JPY
    Assets:全財産
2022/01/27  
    Expenses:食料  332 JPY
    Assets:全財産
2022/01/06  
    Expenses:食料  570 JPY
    Assets:全財産
2022/01/02  
    Expenses:交際費  4320 JPY
    Assets:全財産
  
    Expenses:   JPY
    Assets:全財産

成果物

ledger balance

$ ledger -f genkin.txt bal
        -1120002 JPY  Assets:全財産
         1120002 JPY  Expenses
          105879 JPY    交通・通信
           31149 JPY    交際費
          476000 JPY    住居
           33311 JPY    保健医療
           90348 JPY    家具・家事用品
           24500 JPY    教養娯楽
            2990 JPY    被服及び履物
           83615 JPY    雑費
          272210 JPY    食料
--------------------
                   0

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?