-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsettings.py
34 lines (26 loc) · 1021 Bytes
/
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
from pyrogram import Client
import configparser
import asyncio
import os
import multiprocessing
class Config:
def __init__(self, filename="config.ini"):
self.config = configparser.ConfigParser()
if not os.path.exists(filename):
raise FileNotFoundError(f"Config file '{filename}' not found.")
self.config.read(filename)
def get(self, section, key, fallback=None):
try:
return self.config.get(section, key)
except (configparser.NoSectionError, configparser.NoOptionError):
return fallback
config = Config()
api_id = int(config.get("telegram", "api_id", fallback=0))
api_hash = config.get("telegram", "api_hash", fallback="")
bot_token = config.get("telegram", "bot_token", fallback="")
limit = int(config.get("misc", "limit", fallback=0))
threads = int(config.get("misc", "threads", fallback=0))
if threads == 0:
threads = multiprocessing.cpu_count()
app = Client("my_account", api_id, api_hash)
loop = asyncio.get_event_loop()