1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-12 15:27:14 +03:00

[2251] ResPath Update

This commit is contained in:
David Sangrey 2024-06-06 17:25:51 -04:00
parent 9ddd0ffacc
commit 3209b4e1fb
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC
4 changed files with 23 additions and 7 deletions

View File

@ -208,5 +208,5 @@ def build() -> None:
if __name__ == "__main__":
check_for_fdev_updates()
check_for_fdev_updates(local=True)
build()

View File

@ -22,6 +22,7 @@ from traceback import print_exc
import companion
import outfitting
from config import config
from edmc_data import companion_category_map, ship_name_map
@ -50,7 +51,10 @@ def addcommodities(data) -> None: # noqa: CCR001
if not data['lastStarport'].get('commodities'):
return
commodityfile = pathlib.Path('FDevIDs/commodity.csv')
try:
commodityfile = pathlib.Path(config.app_dir_path / 'FDevIDs' / 'commodity.csv')
except FileNotFoundError:
commodityfile = pathlib.Path('FDevIDs/commodity.csv')
commodities = {}
# slurp existing

View File

@ -1203,10 +1203,10 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully
if not commodity_map:
# Lazily populate
for f in ('commodity.csv', 'rare_commodity.csv'):
if not os.path.isfile(config.respath_path / 'FDevIDs/' / f):
if not os.path.isfile(config.app_dir_path / 'FDevIDs/' / f):
logger.warning(f'FDevID file {f} not found! Generating output without these commodity name rewrites.')
continue
with open(config.respath_path / 'FDevIDs' / f, 'r') as csvfile:
with open(config.app_dir_path / 'FDevIDs' / f, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:

View File

@ -8,6 +8,7 @@ See LICENSE file.
from __future__ import annotations
import pathlib
import shutil
import sys
import threading
from traceback import print_exc
@ -26,21 +27,32 @@ if TYPE_CHECKING:
logger = get_main_logger()
def check_for_fdev_updates(silent: 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."""
if local:
pathway = config.app_dir_path
else:
pathway = config.respath_path
files_urls = [
('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'),
('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv')
]
for file, url in files_urls:
fdevid_file = pathlib.Path(config.respath_path / 'FDevIDs' / file)
fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file)
fdevid_file.parent.mkdir(parents=True, exist_ok=True)
try:
with open(fdevid_file, newline='', encoding='utf-8') as f:
local_content = f.read()
except FileNotFoundError:
local_content = None
logger.info(f'File {file} not found. Writing from bundle...')
for localfile in files_urls:
filepath = f"FDevIDs/{localfile[0]}"
shutil.copy(filepath, pathway / 'FDevIDs')
fdevid_file = pathlib.Path(pathway / 'FDevIDs' / file)
with open(fdevid_file, newline='', encoding='utf-8') as f:
local_content = f.read()
response = requests.get(url)
if response.status_code != 200: