From 319fa1713d16f4391abb10879f6c35f0f4696bcd Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 27 Jul 2023 22:02:38 +0700 Subject: [PATCH] simplify env check for multiple environments --- src/connect.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/connect.py b/src/connect.py index 8365b19..c5e939f 100644 --- a/src/connect.py +++ b/src/connect.py @@ -9,6 +9,7 @@ from src.config import get_config from src.static_types import ConfigType, TAVideo CONFIG: ConfigType = get_config() +EXPECTED_ENV = {"ta_url", "ta_token", "jf_url", "jf_token", "ta_video_path"} class Jellyfin: @@ -99,31 +100,20 @@ class TubeArchivist: def env_check() -> None: - """check if ta_video_path is accessible""" -# if not os.path.exists("config.json"): -# raise FileNotFoundError("config.json file not found") - if not CONFIG["ta_url"]: - raise ValueError("TA_URL not set") - else: - print("TA_URL =", CONFIG["ta_url"]) + """check for expected environment""" - if not CONFIG["ta_token"]: - raise ValueError("TA_TOKEN not set") - else: - print("TA_TOKEN =", CONFIG["ta_token"]) - - if not CONFIG["jf_url"]: - raise ValueError("JF_URL not set") - else: - print("JF_URL =", CONFIG["jf_url"]) - - if not CONFIG["jf_token"]: - raise ValueError("JF_TOKEN not set") - else: - print("JF_TOKEN =", CONFIG["jf_token"]) + if not CONFIG: + raise ValueError("could not build config.") if not os.path.exists(CONFIG["ta_video_path"]): - raise FileNotFoundError("failed to access ta_video_path", CONFIG["ta_video_path"]) + raise FileNotFoundError( + "failed to access ta_video_path", CONFIG["ta_video_path"] + ) + + if not set(CONFIG) == EXPECTED_ENV: + raise ValueError( + f"expected environment {EXPECTED_ENV} but got {set(CONFIG)}" + ) def clean_overview(overview_raw: str) -> str: