-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
52 lines (40 loc) · 1.35 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from configparser import ConfigParser
from dotenv import load_dotenv
import os
import logging
import yaml
load_dotenv()
API_ID = os.getenv('api_id')
API_HASH = os.getenv('api_hash')
STRING_SESSION = os.getenv('STRING_SESSION')
assert API_ID and API_HASH
configur = ConfigParser()
configur.read('config.ini')
forwards = configur.sections()
def get_forward(forward: str) -> tuple:
try:
from_chat = configur.get(forward, 'from')
to_chat = configur.get(forward, 'to')
offset = configur.getint(forward, 'offset')
return from_chat, to_chat, offset
except Exception as err:
logging.exception(
'The content of %s does not follow format. See the README.md file for more details. \n\n %s', forward, str(err))
quit()
def update_offset(forward: str, new_offset: str) -> None:
try:
configur.set(forward, 'offset', new_offset)
with open('config.ini', 'w') as cfg:
configur.write(cfg)
except Exception as err:
logging.exception(
'Problem occured while updating offset of %s \n\n %s', forward, str(err))
if os.path.isfile('replace.yml'):
with open ('replace.yml') as file:
REPLACEMENTS = yaml.full_load(file)
else:
REPLACEMENTS = {}
if __name__ == "__main__":
# testing
for forward in forwards:
print(forward, get_forward(forward))