forked from llomgui/telegram-chat-forward
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
45 lines (34 loc) · 1.2 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
from configparser import ConfigParser
from dotenv import load_dotenv
import os
import logging
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 __name__ == "__main__":
# testing
for forward in forwards:
print(forward, get_forward(forward))