blob: db1e9a7293d3bf8423b7dd71c407963f32afc648 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
import csv
from decimal import Decimal
from typing import List
from ledger_action import LedgerAction
def parse_row(row: dict[str, str]) -> LedgerAction:
return LedgerAction(
type=row["type"],
asset=row["asset"],
amount=Decimal(row["amount"]),
fee=Decimal(row.get("fee", "0")),
refid=row.get("refid", ""),
timestamp=row["time"],
)
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))
|