From b271ad88cb073be18bd87361833a904fffaff2c2 Mon Sep 17 00:00:00 2001 From: "Tech. TTGames" <50541739+Tech-TTGames@users.noreply.github.com> Date: Fri, 17 Mar 2023 23:45:15 +0100 Subject: [PATCH] Revert "Fix pages" (#55) * Revert "Fix pages (#54)" This reverts commit 83c4a676b277a60787640edb3ae1db9fa5de1c99. * Added dry-run default * Full dry run --- tickets_plus/database/statvars.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tickets_plus/database/statvars.py b/tickets_plus/database/statvars.py index 4ff480d..8a28a2c 100644 --- a/tickets_plus/database/statvars.py +++ b/tickets_plus/database/statvars.py @@ -24,7 +24,7 @@ import pathlib import string from logging import handlers -from typing import TYPE_CHECKING, Any, Literal +from typing import Any, Literal import discord import sqlalchemy @@ -76,13 +76,16 @@ def __init__(self) -> None: We also store the token in self.token for easy access. """ self._file = pathlib.Path(PROG_DIR, "secret.json") - if not TYPE_CHECKING: + try: + with open(self._file, encoding="utf-8", mode="r") as secret_f: + self.secrets = json.load(secret_f) + self.token: str = self.secrets["token"] + except FileNotFoundError: + logging.warning("Running in dry-run mode.") + self._file = pathlib.Path(PROG_DIR, "example_secret.json") with open(self._file, encoding="utf-8", mode="r") as secret_f: self.secrets = json.load(secret_f) self.token: str = self.secrets["token"] - else: - self.secrets = {} - self.token = "" def __repr__(self) -> str: return "[OBFUSCATED]" @@ -103,11 +106,14 @@ class MiniConfig: def __init__(self) -> None: self._file = pathlib.Path(PROG_DIR, "config.json") - if not TYPE_CHECKING: + try: + with open(self._file, encoding="utf-8", mode="r") as config_f: + self._config: dict = json.load(config_f) + except FileNotFoundError: + logging.warning("Running in dry-run mode.") + self._file = pathlib.Path(PROG_DIR, "example_config.json") with open(self._file, encoding="utf-8", mode="r") as config_f: self._config: dict = json.load(config_f) - else: - self._config: dict = {} def __dict__(self) -> dict: return self._config