22import json
33from abc import ABC , abstractmethod
44from dataclasses import asdict
5+ from pathlib import Path
6+ from typing import Union
57
68import toml
79
810from .digital_currency_address import DigitalCurrencyAddress
911
12+ PathOrStrPath = Union [Path , str ]
13+
1014
1115class Writer (ABC ):
1216 @abstractmethod
13- def write (self , data : list [DigitalCurrencyAddress ], output_path : str ) -> None : ...
17+ def write (
18+ self , data : list [DigitalCurrencyAddress ], output_path : PathOrStrPath
19+ ) -> None :
20+ """
21+ Format content and write file.
22+
23+ Params
24+ ------
25+ data (list[DigitalCurrencyAddress]): List of parsed cryptocurrency address entries
26+ output_path (PathOrStrPath): Path to file to write formatted content
27+ """
28+ ...
1429
1530
1631class JSONWriter (Writer ):
17- def write (self , data : list [DigitalCurrencyAddress ], output_path : str ) -> None :
32+ def write (
33+ self , data : list [DigitalCurrencyAddress ], output_path : PathOrStrPath
34+ ) -> None :
1835 with open (output_path , "w" , encoding = "utf-8" ) as f :
1936 json .dump ([asdict (entry ) for entry in data ], f , indent = 2 )
2037
2138
2239class TOMLWriter (Writer ):
23- def write (self , data : list [DigitalCurrencyAddress ], output_path : str ) -> None :
40+ def write (
41+ self , data : list [DigitalCurrencyAddress ], output_path : PathOrStrPath
42+ ) -> None :
2443 with open (output_path , "w" , encoding = "utf-8" ) as f :
2544 toml .dump ({"entries" : [asdict (entry ) for entry in data ]}, f )
2645
2746
2847class CSVWriter (Writer ):
29- def write (self , data : list [DigitalCurrencyAddress ], output_path : str ) -> None :
48+ def write (
49+ self , data : list [DigitalCurrencyAddress ], output_path : PathOrStrPath
50+ ) -> None :
3051 if not data :
3152 return
3253
@@ -39,7 +60,9 @@ def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
3960
4061
4162class TextWriter (Writer ):
42- def write (self , data : list [DigitalCurrencyAddress ], output_path : str ) -> None :
63+ def write (
64+ self , data : list [DigitalCurrencyAddress ], output_path : PathOrStrPath
65+ ) -> None :
4366 with open (output_path , "w" , encoding = "utf-8" ) as f :
4467 for entry in data :
4568 for key , value in asdict (entry ).items ():
0 commit comments