import os import requests from dotenv import load_dotenv import client_config as usrcfg load_dotenv() MONITOR_SERVER_INTERFACE = os.environ.get("HOST", "localhost") MONITOR_SERVER_PORT = int(os.environ.get("PORT", 50001)) CHANNEL_IP = f"{MONITOR_SERVER_INTERFACE}:{MONITOR_SERVER_PORT}" AUTHORIZATION = os.environ.get("STORYTELLINGS_AUTH") class BotScriptGetter: @classmethod def from_url(cls, url, script_type, variables): response = requests.get(url, headers={'Authorization': AUTHORIZATION}) data = response.text.encode("utf-8") return data, script_type, variables @classmethod def from_file(cls, filename, script_type, variables): with open(filename, 'r') as f: data = f.read() data = data.encode("utf-8") return data, script_type, variables @classmethod def from_scenario(cls, name): script_config = usrcfg.script_and_config.get(name, {}) script_type = script_config.get("type") variables = script_config.get("var", {}) if "url" in script_config: return cls.from_url(script_config.get("url"), script_type, variables) elif "path" in script_config: return cls.from_file(script_config.get("path"), script_type, variables)