Cleansy/src/config/config_parser.py
2024-07-07 08:17:04 +03:30

48 lines
1.5 KiB
Python

import os
from configparser import ConfigParser
CONFIG_FILE_PATH = 'config.ini'
class Config:
def __init__(self):
self.config = ConfigParser()
self.config_file = 'config.ini'
self.get_config()
def check_config_exists(self):
if os.path.exists(self.config_file):
return True
else:
return False
def get_config(self):
if self.check_config_exists():
try:
self.config.read(self.config_file)
homeserver = self.config.get('synapse', 'homeserver')
access_token = self.config.get('synapse', 'access_token')
return homeserver, access_token
except Exception as e:
print(f"Error reading config file: {e}")
return None, None
else:
homeserver = input("Enter homeserver url: ")
access_token = input("Enter access token: ")
if homeserver and access_token:
self.config['synapse'] = {
'homeserver': homeserver,
'access_token': access_token
}
with open(self.config_file, 'w') as configfile:
self.config.write(configfile)
def get_excluded_users(self):
try:
self.config.read(self.config_file)
excluded_users = self.config.get('options', 'excluded_users').split(',')
return excluded_users
except Exception as e:
print(f"Error reading config file: {e}")
return []