replace-bot/configs/configure.py

35 lines
1.2 KiB
Python
Raw Normal View History

2022-02-16 18:13:44 +03:00
from configparser import ConfigParser
from easydict import EasyDict as edict
2022-02-16 18:13:44 +03:00
CONFIG_FILE = 'config.ini'
class Configure:
2022-02-16 18:13:44 +03:00
def __init__(self):
config = ConfigParser()
config.read(CONFIG_FILE)
2022-02-16 18:13:44 +03:00
self.data = dict()
for section in config.sections():
2022-02-16 18:13:44 +03:00
self.data[section] = dict()
for key, value in config.items(section):
2022-02-16 18:13:44 +03:00
self.data[section][key] = value
2023-09-04 23:34:52 +03:00
config_folder = config.get("Docs_Settings", "Config_folder").rstrip("/")
self.data["documentid"] = config.get("Docs_Settings", 'Document_ID')
self.data["data_file"] = config_folder + "/" + config.get("Docs_Settings", "data_file")
self.data["credentials_file"] = config_folder + "/" + config.get("Docs_Settings", "credentials_file")
self.data["token_file"] = self.config_folder + "/" + self.data['Docs_Settings']['token_file']
def __getattr__(self, name):
2023-09-04 23:34:52 +03:00
if name in ["documentid", "data_file", "credentials_file", "token_file"]:
return self.data[name]
for key in self.data.keys():
if name not in self.data[key]:
continue
return self.data[key][name]
2023-09-04 23:34:52 +03:00
# raise NameError("Config options not found!")