-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram_client.py
More file actions
27 lines (20 loc) · 831 Bytes
/
Copy pathtelegram_client.py
File metadata and controls
27 lines (20 loc) · 831 Bytes
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
from telethon import TelegramClient
import configparser
import json
class TeleClient:
def __init__(self, config_file='configs/telegram_client_config.ini') -> None:
config = configparser.ConfigParser()
config.read(config_file)
self.init_client(config)
def init_client(self, config):
creds = None
with open(config['DEFAULT']['creds_file'], "r") as file:
creds = json.load(file)
self.client = TelegramClient(config['DEFAULT']['session_path'], creds['app_id'], creds['api_hash'])
#self.client.session.save_entities = False
async def async_get_me(self):
me = await self.client.get_me()
print(me.stringify())
def get_me(self):
with self.client:
self.client.loop.run_until_complete(self.async_get_me())