Change folder "json" to "assets" and add reload_assets function

This commit is contained in:
M-307 2022-07-17 13:08:16 +07:00
parent 1bb158e00c
commit 9e3a9a57af
2 changed files with 14 additions and 11 deletions

View File

@ -26,10 +26,13 @@ class Assets:
def __init__(self, lang: Language = Language.EN) -> None:
# Set language
self.__set_languege(lang)
self.reload_assets()
@classmethod
def reload_assets(cls) -> None:
# Load assets
self.__load_assets_lang()
self.__load_assets_data()
cls.__load_assets_lang()
cls.__load_assets_data()
@classmethod
def character(cls, id: int) -> Union[assets.CharacterAsset, None]:
@ -131,15 +134,15 @@ class Assets:
cls.LANGS = lang.upper()
@classmethod
def __get_path_assets(cls) -> Dict[str, str]:
def _get_path_assets(cls) -> Dict[str, str]:
return {
"data": os.path.join(PATH, "json", "data"),
"langs": os.path.join(PATH, "json", "langs")
"data": os.path.join(PATH, "assets", "data"),
"langs": os.path.join(PATH, "assets", "langs")
}
@classmethod
def __load_assets_lang(cls) -> None:
_PATH = cls.__get_path_assets()["langs"]
_PATH = cls._get_path_assets()["langs"]
FILE_LANG = os.listdir(_PATH)
for FILENAME in FILE_LANG:
LOGGER.debug(f"Loading language file {FILENAME}...")
@ -147,7 +150,7 @@ class Assets:
@classmethod
def __load_assets_data(cls) -> None:
_PATH = cls.__get_path_assets()["data"]
_PATH = cls._get_path_assets()["data"]
FILE_DATA = os.listdir(_PATH)
for FILENAME in FILE_DATA:
LOGGER.debug(f"Loading data file {FILENAME}...")

View File

@ -52,9 +52,9 @@ class EnkaNetworkAPI:
self.LOGGER.debug("Parsing data...")
return EnkaNetworkResponse.parse_obj(data)
async def download_data(self) -> None:
async def update_assets(self) -> None:
self.LOGGER.debug("Downloading new content...")
_PATH = Assets.get_path_json()
_PATH = Assets._get_path_assets()
for folder in _PATH:
for filename in os.listdir(_PATH[folder]):
self.LOGGER.debug(f"Downloading {folder} file {filename}...")
@ -66,5 +66,5 @@ class EnkaNetworkAPI:
with open(os.path.join(_PATH[folder], filename), "w", encoding="utf-8") as f:
json.dump(_json["content"], f, ensure_ascii=False, indent=4)
# Load config
self.__load_config(Assets.LANGS)
# Reload config
self.assets.reload_assets()