Add cli option
This commit is contained in:
@@ -34,6 +34,8 @@ def main():
|
|||||||
help='Output directory (end with "/"). default="./"', default='./')
|
help='Output directory (end with "/"). default="./"', default='./')
|
||||||
parser.add_argument(f'--{Arguments.Name.VERSION}', action='store_true',
|
parser.add_argument(f'--{Arguments.Name.VERSION}', action='store_true',
|
||||||
help='Show version')
|
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__)
|
Arguments(parser.parse_args().__dict__)
|
||||||
if Arguments().print_version:
|
if Arguments().print_version:
|
||||||
print(f'pytchat v{__version__} © 2019 taizan-hokuto')
|
print(f'pytchat v{__version__} © 2019 taizan-hokuto')
|
||||||
@@ -82,10 +84,12 @@ def main():
|
|||||||
except JSONDecodeError as e:
|
except JSONDecodeError as e:
|
||||||
print(e.msg)
|
print(e.msg)
|
||||||
print("Cannot parse video information.:{}".format(video_id))
|
print("Cannot parse video information.:{}".format(video_id))
|
||||||
|
if Arguments().save_error_data:
|
||||||
util.save(e.doc, "ERR_JSON_DECODE", ".dat")
|
util.save(e.doc, "ERR_JSON_DECODE", ".dat")
|
||||||
except PatternUnmatchError as e:
|
except PatternUnmatchError as e:
|
||||||
print(e.msg)
|
print(e.msg)
|
||||||
print("Cannot parse video information.:{}".format(video_id))
|
print("Cannot parse video information.:{}".format(video_id))
|
||||||
|
if Arguments().save_error_data:
|
||||||
util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat")
|
util.save(e.doc, "ERR_PATTERN_UNMATCH", ".dat")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class Arguments(metaclass=Singleton):
|
|||||||
VERSION: str = 'version'
|
VERSION: str = 'version'
|
||||||
OUTPUT: str = 'output_dir'
|
OUTPUT: str = 'output_dir'
|
||||||
VIDEO_IDS: str = 'video_id'
|
VIDEO_IDS: str = 'video_id'
|
||||||
|
SAVE_ERROR_DATA: bool = 'save_error_data'
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
arguments: Optional[Dict[str, Union[str, bool, int]]] = None):
|
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.print_version: bool = arguments[Arguments.Name.VERSION]
|
||||||
self.output: str = arguments[Arguments.Name.OUTPUT]
|
self.output: str = arguments[Arguments.Name.OUTPUT]
|
||||||
self.video_ids: List[int] = []
|
self.video_ids: List[int] = []
|
||||||
|
self.save_error_data: bool = arguments[Arguments.Name.SAVE_ERROR_DATA]
|
||||||
# Videos
|
# Videos
|
||||||
if arguments[Arguments.Name.VIDEO_IDS]:
|
if arguments[Arguments.Name.VIDEO_IDS]:
|
||||||
self.video_ids = [video_id
|
self.video_ids = [video_id
|
||||||
|
|||||||
Reference in New Issue
Block a user