blob: 9048a7dd190c4a9c8d94946ff22b81d06839173e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import csv
from decimal import Decimal
from typing import List
from ledger_action import LedgerAction
def parse_row(row: dict[str, str]) -> LedgerAction:
date = row["time"].split(" ")[0]
return LedgerAction(
type=row["type"],
asset=row["asset"],
amount=Decimal(row["amount"]),
fee=Decimal(row.get("fee", "0")),
refid=row.get("refid", ""),
date=date,
)
def read_ledger(csv_path: str) -> List[LedgerAction]:
with open(csv_path, "r") as file:
reader = csv.DictReader(file)
return list(map(parse_row, reader))
|