from configparser import ConfigParser from typing import Any CONFIG_FILE = 'config.ini' class Cfg: def __getattr__(self, name: str) -> Any: for key in self.data.keys(): if name not in self.data[key]: continue return self.data[key][name] raise NameError("Config options not found!") class Configure(Cfg): def __init__(self): config = ConfigParser() config.read(CONFIG_FILE) self.config = config self.data = dict() for section in config.sections(): self.data[section] = dict() for key, value in config.items(section): self.data[section][key] = value self.config_folder = config.get("Docs_Settings", "Config_folder").rstrip("/") @property def documentid(self): return self.config.get("Docs_Settings", 'Document_ID') @property def data_file(self): return self.config_folder + "/" + self.config.get("Docs_Settings", "data_file") @property def credentials_file(self): return self.config_folder + "/" + self.config.get("Docs_Settings", "credentials_file") @property def token_file(self): return self.config_folder + "/" + self.data['Docs_Settings']['token_file']