1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-06 10:23:06 +03:00

[2251] Remember the File May Not Exist

This commit is contained in:
David Sangrey 2024-06-06 18:08:03 -04:00
parent 76c94bfdb9
commit 1f92c0cdfb
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC

View File

@ -30,9 +30,9 @@ logger = get_main_logger()
def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None: # noqa: CCR001 def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None: # noqa: CCR001
"""Check for and download FDEV ID file updates.""" """Check for and download FDEV ID file updates."""
if local: if local:
pathway = config.app_dir_path
else:
pathway = config.respath_path pathway = config.respath_path
else:
pathway = config.app_dir_path
files_urls = [ files_urls = [
('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'), ('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'),
@ -47,12 +47,15 @@ def check_for_fdev_updates(silent: bool = False, local: bool = False) -> None:
local_content = f.read() local_content = f.read()
except FileNotFoundError: except FileNotFoundError:
logger.info(f'File {file} not found. Writing from bundle...') logger.info(f'File {file} not found. Writing from bundle...')
for localfile in files_urls: try:
filepath = f"FDevIDs/{localfile[0]}" for localfile in files_urls:
shutil.copy(filepath, pathway / 'FDevIDs') filepath = f"FDevIDs/{localfile[0]}"
fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file) shutil.copy(filepath, pathway / 'FDevIDs')
with open(fdevid_file, newline='', encoding='utf-8') as f: fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file)
local_content = f.read() with open(fdevid_file, newline='', encoding='utf-8') as f:
local_content = f.read()
except FileNotFoundError:
local_content = None
response = requests.get(url, timeout=20) response = requests.get(url, timeout=20)
if response.status_code != 200: if response.status_code != 200: