mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-12 23:37:14 +03:00
[2251] ResPath Update
This commit is contained in:
parent
9ddd0ffacc
commit
3209b4e1fb
2
build.py
2
build.py
@ -208,5 +208,5 @@ def build() -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
check_for_fdev_updates()
|
check_for_fdev_updates(local=True)
|
||||||
build()
|
build()
|
||||||
|
@ -22,6 +22,7 @@ from traceback import print_exc
|
|||||||
|
|
||||||
import companion
|
import companion
|
||||||
import outfitting
|
import outfitting
|
||||||
|
from config import config
|
||||||
from edmc_data import companion_category_map, ship_name_map
|
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'):
|
if not data['lastStarport'].get('commodities'):
|
||||||
return
|
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 = {}
|
commodities = {}
|
||||||
|
|
||||||
# slurp existing
|
# slurp existing
|
||||||
|
@ -1203,10 +1203,10 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully
|
|||||||
if not commodity_map:
|
if not commodity_map:
|
||||||
# Lazily populate
|
# Lazily populate
|
||||||
for f in ('commodity.csv', 'rare_commodity.csv'):
|
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.')
|
logger.warning(f'FDevID file {f} not found! Generating output without these commodity name rewrites.')
|
||||||
continue
|
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)
|
reader = csv.DictReader(csvfile)
|
||||||
|
|
||||||
for row in reader:
|
for row in reader:
|
||||||
|
18
update.py
18
update.py
@ -8,6 +8,7 @@ See LICENSE file.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
@ -26,21 +27,32 @@ if TYPE_CHECKING:
|
|||||||
logger = get_main_logger()
|
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."""
|
"""Check for and download FDEV ID file updates."""
|
||||||
|
if local:
|
||||||
|
pathway = config.app_dir_path
|
||||||
|
else:
|
||||||
|
pathway = config.respath_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'),
|
||||||
('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv')
|
('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv')
|
||||||
]
|
]
|
||||||
|
|
||||||
for file, url in files_urls:
|
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)
|
fdevid_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
try:
|
try:
|
||||||
with open(fdevid_file, newline='', encoding='utf-8') as f:
|
with open(fdevid_file, newline='', encoding='utf-8') as f:
|
||||||
local_content = f.read()
|
local_content = f.read()
|
||||||
except FileNotFoundError:
|
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)
|
response = requests.get(url)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user