2022-02-16 18:13:44 +03:00
|
|
|
from configparser import ConfigParser
|
2023-03-28 09:49:46 +03:00
|
|
|
from easydict import EasyDict as edict
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
CONFIG_FILE = 'config.ini'
|
|
|
|
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
class Configure:
|
2022-02-16 18:13:44 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
2023-03-28 09:49:46 +03:00
|
|
|
config = ConfigParser()
|
|
|
|
config.read(CONFIG_FILE)
|
2022-02-16 18:13:44 +03:00
|
|
|
self.data = dict()
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
for section in config.sections():
|
2022-02-16 18:13:44 +03:00
|
|
|
self.data[section] = dict()
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
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']
|
|
|
|
|
2023-03-28 09:49:46 +03:00
|
|
|
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]
|
2023-03-28 09:49:46 +03:00
|
|
|
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!")
|