Add cli option
This commit is contained in:
@@ -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,10 +84,12 @@ def main():
|
||||
except JSONDecodeError as e:
|
||||
print(e.msg)
|
||||
print("Cannot parse video information.:{}".format(video_id))
|
||||
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))
|
||||
if Arguments().save_error_data:
|
||||
util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat")
|
||||
|
||||
return
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user