refactor: move json file dumping to separate method
This commit is contained in:
+11
-2
@@ -19,6 +19,15 @@ from freqtrade.enums import SignalTagType, SignalType
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def dump_json_to_file(file_obj: TextIO, data: Any) -> None:
|
||||||
|
"""
|
||||||
|
Dump JSON data into a file object
|
||||||
|
:param file_obj: File object to write to
|
||||||
|
:param data: JSON Data to save
|
||||||
|
"""
|
||||||
|
rapidjson.dump(data, file_obj, default=str, number_mode=rapidjson.NM_NATIVE)
|
||||||
|
|
||||||
|
|
||||||
def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool = True) -> None:
|
def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
Dump JSON data into a file
|
Dump JSON data into a file
|
||||||
@@ -35,12 +44,12 @@ def file_dump_json(filename: Path, data: Any, is_zip: bool = False, log: bool =
|
|||||||
logger.info(f'dumping json to "{filename}"')
|
logger.info(f'dumping json to "{filename}"')
|
||||||
|
|
||||||
with gzip.open(filename, "wt", encoding="utf-8") as fpz:
|
with gzip.open(filename, "wt", encoding="utf-8") as fpz:
|
||||||
rapidjson.dump(data, fpz, default=str, number_mode=rapidjson.NM_NATIVE)
|
dump_json_to_file(fpz, data)
|
||||||
else:
|
else:
|
||||||
if log:
|
if log:
|
||||||
logger.info(f'dumping json to "{filename}"')
|
logger.info(f'dumping json to "{filename}"')
|
||||||
with filename.open("w") as fp:
|
with filename.open("w") as fp:
|
||||||
rapidjson.dump(data, fp, default=str, number_mode=rapidjson.NM_NATIVE)
|
dump_json_to_file(fp, data)
|
||||||
|
|
||||||
logger.debug(f'done json to "{filename}"')
|
logger.debug(f'done json to "{filename}"')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user