From 3bcad12cf625df78d77fbbdf966cf2dbcd146b24 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Thu, 3 Sep 2020 19:31:34 +0900 Subject: [PATCH] Add cli option --- pytchat/cli/__init__.py | 8 ++++++-- pytchat/cli/arguments.py | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pytchat/cli/__init__.py b/pytchat/cli/__init__.py index 75a56e3..a7f045f 100644 --- a/pytchat/cli/__init__.py +++ b/pytchat/cli/__init__.py @@ -34,6 +34,8 @@ def main(): help='Output directory (end with "/"). default="./"', default='./') parser.add_argument(f'--{Arguments.Name.VERSION}', action='store_true', help='Show version') + parser.add_argument(f'--{Arguments.Name.SAVE_ERROR_DATA}', action='store_true', + help='Save error data when error occurs(".dat" file)') Arguments(parser.parse_args().__dict__) if Arguments().print_version: print(f'pytchat v{__version__} © 2019 taizan-hokuto') @@ -82,11 +84,13 @@ def main(): except JSONDecodeError as e: print(e.msg) print("Cannot parse video information.:{}".format(video_id)) - util.save(e.doc, "ERR_JSON_DECODE", ".dat") + if Arguments().save_error_data: + util.save(e.doc, "ERR_JSON_DECODE", ".dat") except PatternUnmatchError as e: print(e.msg) print("Cannot parse video information.:{}".format(video_id)) - util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat") + if Arguments().save_error_data: + util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat") return diff --git a/pytchat/cli/arguments.py b/pytchat/cli/arguments.py index 6f62548..d034f93 100644 --- a/pytchat/cli/arguments.py +++ b/pytchat/cli/arguments.py @@ -18,7 +18,7 @@ class Arguments(metaclass=Singleton): VERSION: str = 'version' OUTPUT: str = 'output_dir' VIDEO_IDS: str = 'video_id' - + SAVE_ERROR_DATA: bool = 'save_error_data' def __init__(self, arguments: Optional[Dict[str, Union[str, bool, int]]] = None): """ @@ -34,6 +34,7 @@ class Arguments(metaclass=Singleton): self.print_version: bool = arguments[Arguments.Name.VERSION] self.output: str = arguments[Arguments.Name.OUTPUT] self.video_ids: List[int] = [] + self.save_error_data: bool = arguments[Arguments.Name.SAVE_ERROR_DATA] # Videos if arguments[Arguments.Name.VIDEO_IDS]: self.video_ids = [video_id