From 315ea77b67b25565c1171852eb3481326739c1fe Mon Sep 17 00:00:00 2001 From: Abhijeet Krishnan Date: Fri, 16 Feb 2024 13:57:04 -0500 Subject: [PATCH] Move static files out of src --- pyproject.toml | 1 - requirements.txt | 1 - src/frame_service/json_directory/__init__.py | 1 - .../json_directory/json_directory.py | 41 ------------------- .../json_directory/tests/json_directory.py | 10 ----- src/main.py | 32 +++++++++++---- {src/static => static}/config.sample.json | 0 {src/static => static}/schema.json | 0 8 files changed, 24 insertions(+), 62 deletions(-) delete mode 100644 src/frame_service/json_directory/__init__.py delete mode 100644 src/frame_service/json_directory/json_directory.py delete mode 100644 src/frame_service/json_directory/tests/json_directory.py rename {src/static => static}/config.sample.json (100%) rename {src/static => static}/schema.json (100%) diff --git a/pyproject.toml b/pyproject.toml index 9cceacc..1cba04a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,6 @@ requires-python = ">= 3.10" dependencies = [ "discord.py", "beautifulsoup4", - "pymediawiki", "Requests", "lxml" ] diff --git a/requirements.txt b/requirements.txt index de840d6..71eb03d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ beautifulsoup4 discord.py -pymediawiki Requests lxml diff --git a/src/frame_service/json_directory/__init__.py b/src/frame_service/json_directory/__init__.py deleted file mode 100644 index e944084..0000000 --- a/src/frame_service/json_directory/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .json_directory import JsonDirectory diff --git a/src/frame_service/json_directory/json_directory.py b/src/frame_service/json_directory/json_directory.py deleted file mode 100644 index 45424e9..0000000 --- a/src/frame_service/json_directory/json_directory.py +++ /dev/null @@ -1,41 +0,0 @@ -import json -import logging -import os - -from framedb import Character, CharacterName, FrameService, Move - -logger = logging.getLogger("main") - - -class JsonDirectory(FrameService): - def __init__(self, char_meta_dir: str, movelist_dir: str) -> None: - self.name = f"JSON Directory ({movelist_dir})" - self.icon = None - self.movelist_dir = movelist_dir - - try: - with open(char_meta_dir, "r") as f: - self.character_meta = json.load(f) - except Exception as e: - raise Exception(f"Could not load character meta data from {char_meta_dir}") from e - - def get_frame_data(self, character: CharacterName) -> Character: - # TODO: duplicated across wavu and json_directory -> refactor - target_char_meta = None - for char_meta in self.character_meta: - if char_meta["name"] == character.value: - target_char_meta = char_meta - break - if target_char_meta is None: - raise Exception(f"Could not find character meta data for {character.value}") - - name = CharacterName(target_char_meta["name"]) - portrait = target_char_meta["portrait"] - page = target_char_meta["page"] - - filepath = os.path.abspath(os.path.join(self.movelist_dir, f"{character.value}.json")) - with open(filepath, encoding="utf-8") as move_file: - move_file_contents = json.load(move_file) - movelist = {move["id"]: Move(**move) for move in move_file_contents} - char = Character(name, portrait, movelist, page) - return char diff --git a/src/frame_service/json_directory/tests/json_directory.py b/src/frame_service/json_directory/tests/json_directory.py deleted file mode 100644 index cf966fc..0000000 --- a/src/frame_service/json_directory/tests/json_directory.py +++ /dev/null @@ -1,10 +0,0 @@ -import os - -from frame_service.json_directory import json_directory - -STATIC_BASE = os.path.join(os.path.dirname(__file__), "static") - - -def test_get_movelist_from_json() -> None: - result = json_directory.get_movelist("azucena", STATIC_BASE) - assert result[0].id == "Azucena-1" diff --git a/src/main.py b/src/main.py index 2c43822..d35e009 100644 --- a/src/main.py +++ b/src/main.py @@ -2,17 +2,17 @@ """The entry point for the bot.""" +import argparse import logging import os import sched -import sys import threading import time from typing import Any, Callable, Tuple from frame_service import Wavu from framedb import FrameDb -from heihachi import configurator +from heihachi import Configurator from heihachi.bot import FrameDataBot "How often to update the bot's frame data from the external service and write to file." @@ -36,19 +36,35 @@ def periodic_function(scheduler: sched.scheduler, interval: float, function: Cal scheduler.run() +def get_argparser() -> argparse.ArgumentParser: + parser = argparse.ArgumentParser(description="Heihachi bot") + parser.add_argument("config_file", type=str, help="Path to the config file") + parser.add_argument( + "--export_dir", + type=str, + default=os.path.join(os.getcwd(), "json_movelist"), + help="Path to the directory to export frame data to", + ) + parser.add_argument("--format", type=str, default="json", help="Format to export frame data to") + return parser + + def main() -> None: + parser = get_argparser() + args = parser.parse_args() + config_file_path = args.config_file + export_dir_path = args.export_dir + _format = args.format + # retrieve config try: - config = configurator.Configurator.from_file(sys.argv[1]) # TODO: potentially use argparse + config = Configurator.from_file(config_file_path) assert config is not None - logger.info(f"Config file loaded from {sys.argv[1]}") + logger.info(f"Config file loaded from {config_file_path}") except FileNotFoundError: - logger.error(f"Config file not found at {sys.argv[1]}. Exiting...") + logger.error(f"Config file not found at {config_file_path}. Exiting...") exit(1) - export_dir_path = os.path.join(os.getcwd(), "json_movelist") - _format = "json" - # initialize bot try: frame_service = Wavu() diff --git a/src/static/config.sample.json b/static/config.sample.json similarity index 100% rename from src/static/config.sample.json rename to static/config.sample.json diff --git a/src/static/schema.json b/static/schema.json similarity index 100% rename from src/static/schema.json rename to static/schema.json