diff --git a/ADC_function.py b/ADC_function.py index e310dd5..993e5dc 100644 --- a/ADC_function.py +++ b/ADC_function.py @@ -381,7 +381,7 @@ def load_cookies(cookie_json_filename: str): break if not cookies_filename: return None, None - return json.load(open(cookies_filename)), cookies_filename + return json.loads(Path(cookies_filename).read_text(encoding='utf-8')), cookies_filename except: return None, None @@ -519,14 +519,13 @@ def download_one_file(args) -> str: wrapped for map function """ - def _inner(url: str, save_path: Path): - filebytes = get_html(url, return_type='content') - if isinstance(filebytes, bytes) and len(filebytes): - if len(filebytes) == save_path.open('wb').write(filebytes): + (url, save_path) = args + filebytes = get_html(url, return_type='content') + if isinstance(filebytes, bytes) and len(filebytes): + with save_path.open('wb') as fpbyte: + if len(filebytes) == fpbyte.write(filebytes): return str(save_path) - return _inner(*args) - def parallel_download_files(dn_list: typing.Iterable[typing.Sequence], parallel: int = 0): """ diff --git a/WebCrawler/__init__.py b/WebCrawler/__init__.py index 7f9cf19..d870ece 100644 --- a/WebCrawler/__init__.py +++ b/WebCrawler/__init__.py @@ -248,8 +248,8 @@ def get_data_from_json(file_number, oCC): if json_data[translate_value] == "": continue if translate_value == "title": - title_dict = json.load( - open(str(Path.home() / '.local' / 'share' / 'mdc' / 'c_number.json'), 'r', encoding="utf-8")) + title_dict = json.loads( + (Path.home() / '.local' / 'share' / 'mdc' / 'c_number.json').read_text(encoding="utf-8")) try: json_data[translate_value] = title_dict[number] continue