2024-08-12 17:25:30 +03:00
|
|
|
from configparser import RawConfigParser
|
|
|
|
import os
|
|
|
|
|
2024-08-13 17:46:44 +03:00
|
|
|
import redis
|
2024-08-13 00:00:41 +03:00
|
|
|
|
2024-08-12 17:25:30 +03:00
|
|
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
config = RawConfigParser()
|
|
|
|
config.read(
|
|
|
|
filenames=os.path.join(
|
|
|
|
cwd,
|
|
|
|
'config.ini',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-08-13 17:46:44 +03:00
|
|
|
class Main:
|
|
|
|
cwd = config.get(
|
|
|
|
section='Main',
|
|
|
|
option='cwd',
|
|
|
|
fallback=os.getcwd(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Postgres:
|
|
|
|
host = config.get(
|
|
|
|
section='Postgres',
|
|
|
|
option='host',
|
|
|
|
fallback='localhost',
|
|
|
|
)
|
|
|
|
port = config.getint(
|
|
|
|
section='Postgres',
|
|
|
|
option='port',
|
|
|
|
fallback=5432,
|
|
|
|
)
|
|
|
|
user = config.get(
|
|
|
|
section='Postgres',
|
|
|
|
option='user',
|
2024-08-12 17:25:30 +03:00
|
|
|
)
|
2024-08-13 17:46:44 +03:00
|
|
|
password = config.get(
|
|
|
|
section='Postgres',
|
|
|
|
option='password',
|
|
|
|
)
|
|
|
|
dbname = config.get(
|
|
|
|
section='Postgres',
|
|
|
|
option='dbname',
|
|
|
|
)
|
|
|
|
|
2024-08-13 00:00:41 +03:00
|
|
|
|
2024-08-13 17:46:44 +03:00
|
|
|
class Redis:
|
|
|
|
host = config.get(
|
|
|
|
section='Redis',
|
|
|
|
option='host',
|
|
|
|
fallback='localhost',
|
|
|
|
)
|
|
|
|
port = config.getint(
|
|
|
|
section='Redis',
|
|
|
|
option='port',
|
|
|
|
fallback=6379,
|
|
|
|
)
|
|
|
|
db = config.get(
|
|
|
|
section='Redis',
|
|
|
|
option='db',
|
|
|
|
)
|
|
|
|
password = config.get(
|
|
|
|
section='Redis',
|
|
|
|
option='password',
|
|
|
|
fallback=None,
|
|
|
|
)
|
2024-08-13 00:00:41 +03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(
|
|
|
|
cls,
|
|
|
|
key: str,
|
|
|
|
):
|
2024-08-13 17:46:44 +03:00
|
|
|
with redis.Redis(
|
|
|
|
host=cls.host,
|
|
|
|
port=cls.port,
|
|
|
|
db=cls.db,
|
|
|
|
password=cls.password,
|
|
|
|
decode_responses=True,
|
|
|
|
) as connection:
|
|
|
|
return connection.get(
|
2024-08-13 00:00:41 +03:00
|
|
|
name=key,
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def set(
|
|
|
|
cls,
|
|
|
|
key: str,
|
|
|
|
value,
|
|
|
|
):
|
2024-08-13 17:46:44 +03:00
|
|
|
with redis.Redis(
|
|
|
|
host=cls.host,
|
|
|
|
port=cls.port,
|
|
|
|
db=cls.db,
|
|
|
|
password=cls.password,
|
2024-08-13 00:00:41 +03:00
|
|
|
decode_responses=True,
|
2024-08-13 17:46:44 +03:00
|
|
|
) as connection:
|
|
|
|
connection.set(
|
2024-08-13 00:00:41 +03:00
|
|
|
name=key,
|
|
|
|
value=value,
|
|
|
|
)
|
2024-08-13 17:46:44 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Telegram:
|
|
|
|
token = config.get(
|
|
|
|
section='Telegram',
|
|
|
|
option='token',
|
|
|
|
)
|