ttc index updater

master
JoYo 2021-12-23 19:06:18 -05:00
parent 432f4128c9
commit ca76d4c605
3 changed files with 35 additions and 1 deletions

View File

@ -36,9 +36,13 @@ def esoui(url: str):
def live(path: Path):
if not path.is_dir():
logging.error(f"unexpected file object {path}, ignoring")
return
meta_file = path.joinpath(f"{path.stem}.txt")
if not meta_file.is_file():
if not meta_file.exists():
for meta_file in path.glob("*.txt"):
if not meta_file.stem in path.stem:
continue

View File

@ -5,6 +5,7 @@ import logging
from . import compare
from . import config
from . import parsing
from . import tamriel_trade_centre
def periodical_script():
@ -67,3 +68,4 @@ def periodical_script():
compare.live_to_esoui(path=child, esoui_uris=esoui_uris)
compare.esoui_to_live(esoui_uris=esoui_uris, live_path=live_path)
tamriel_trade_centre.update(live_path=live_path)

View File

@ -0,0 +1,28 @@
from distutils.dir_util import copy_tree
from io import BytesIO
from pathlib import Path
from tempfile import TemporaryDirectory
from zipfile import ZipFile
import logging
import requests
price_table_uri = "https://us.tamrieltradecentre.com/download/PriceTable"
price_table_name = "TamrielTradeCentre"
def update(live_path: Path):
response = requests.get(price_table_uri)
response.raise_for_status()
temp_dir = TemporaryDirectory()
temp_path = Path(temp_dir.name)
zip_file = ZipFile(BytesIO(response.content))
zip_file.extractall(temp_path)
live_tamriel_trade_centre = live_path.joinpath("TamrielTradeCentre")
copy_tree(str(temp_path.absolute()), str(live_tamriel_trade_centre.absolute()))
logging.info(
f"tamriel trade centre price table updated: {live_tamriel_trade_centre}"
)