CoolFace
Apppublic

animetoon/toon-api

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
load_config.py67 linesDownload Raw Back to root
1import os2import urllib.request3import urllib.error4import sys5 6def main():7    # Check for Gist or Config URL in environment variables8    config_url = os.environ.get("CONFIG_FILE_URL") or os.environ.get("GIST_URL") or os.environ.get("CONFIG_URL")9    10    if not config_url:11        print("[-] CONFIG_FILE_URL, GIST_URL or CONFIG_URL environment variable is not set.")12        print("[-] Checking if config.env exists locally...")13        if os.path.exists("config.env"):14            print("[+] config.env found locally. Proceeding...")15            return16        else:17            print("[-] config.env not found. Please set GIST_URL or CONFIG_FILE_URL in environment variables.")18            sys.exit(1)19 20    # Clean and convert the Gist URL if necessary21    target_url = config_url.strip()22    if "gist.github.com" in target_url and "gist.githubusercontent.com" not in target_url and "/raw" not in target_url:23        if target_url.endswith("/"):24            target_url += "raw"25        else:26            target_url += "/raw"27 28    print(f"[+] Fetching configuration from: {target_url}")29    try:30        req = urllib.request.Request(31            target_url,32            headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}33        )34        with urllib.request.urlopen(req, timeout=15) as response:35            content = response.read().decode('utf-8')36        37        # Write the downloaded content to config.env38        with open("config.env", "w", encoding="utf-8") as f:39            f.write(content)40        41        print("[+] Configuration successfully downloaded and saved to config.env")42        43        # Print a sanitized preview or list of keys to confirm success44        print("[+] Loaded keys:")45        for line in content.splitlines():46            line = line.strip()47            if line and not line.startswith('#'):48                parts = line.split('=', 1)49                key = parts[0].strip()50                print(f"  - {key}")51                52    except urllib.error.URLError as e:53        print(f"[-] Network error fetching configuration: {e}", file=sys.stderr)54        if os.path.exists("config.env"):55            print("[+] Using existing local config.env as fallback.", file=sys.stderr)56        else:57            sys.exit(1)58    except Exception as e:59        print(f"[-] Unexpected error: {e}", file=sys.stderr)60        if os.path.exists("config.env"):61            print("[+] Using existing local config.env as fallback.", file=sys.stderr)62        else:63            sys.exit(1)64 65if __name__ == "__main__":66    main()67