From 05d2829baed2d937e8b9e515f34c83efdf5e0501 Mon Sep 17 00:00:00 2001 From: CramMK Date: Wed, 12 Feb 2020 16:58:01 +0100 Subject: [PATCH] add yml config option --- config/config_example.yml | 6 ++++++ loadconfig.py | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 config/config_example.yml diff --git a/config/config_example.yml b/config/config_example.yml new file mode 100644 index 0000000..9733a63 --- /dev/null +++ b/config/config_example.yml @@ -0,0 +1,6 @@ +--- + +token: '' +prefix: '' + +... diff --git a/loadconfig.py b/loadconfig.py index 2791ea2..2252af4 100644 --- a/loadconfig.py +++ b/loadconfig.py @@ -1,13 +1,26 @@ """ -Gather all config data into one file +Gather all config data into one file, +so all other files can call it from here loadconfig.py then gets called in aquabot.py """ +# IMPORTS +import yaml + +# Variable Gathering __avatar__ = "https://i.imgur.com/mskM9dH.png" try: - # TODO Maybe use yaml for token and prefix! + with open("config/config.yml") as file: + config = yaml.safe_load(file) + for yml_entry in config: + __token__ = config[yml_entry]['token'] + __prefix__ = config[yml_entry]['prefix'] +except yaml.YAMLError as error: + print(f"Error while parsing: {error}") + +try: from config.config import __token__, __prefix__ from config.cogs import __cogs__ from config.status import __activity__