replace-bot/configs/configure.py

47 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-02-16 18:13:44 +03:00
from configparser import ConfigParser
from typing import Any
2022-02-16 18:13:44 +03:00
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):
2022-02-16 18:13:44 +03:00
def __init__(self):
config = ConfigParser()
config.read(CONFIG_FILE)
self.config = config
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
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']