From ca76d4c6053ec50d5dc5615ef30bf944075b2e54 Mon Sep 17 00:00:00 2001 From: JoYo <> Date: Thu, 23 Dec 2021 19:06:18 -0500 Subject: [PATCH] ttc index updater --- banana/parsing.py | 6 +++++- banana/scripts.py | 2 ++ banana/tamriel_trade_centre.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 banana/tamriel_trade_centre.py diff --git a/banana/parsing.py b/banana/parsing.py index 7fbceb1..0533166 100644 --- a/banana/parsing.py +++ b/banana/parsing.py @@ -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 diff --git a/banana/scripts.py b/banana/scripts.py index e9bde9e..4e9a83e 100644 --- a/banana/scripts.py +++ b/banana/scripts.py @@ -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) diff --git a/banana/tamriel_trade_centre.py b/banana/tamriel_trade_centre.py new file mode 100644 index 0000000..47ea6e7 --- /dev/null +++ b/banana/tamriel_trade_centre.py @@ -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}" + )