forked from mtrineyev/tgtorss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.py
31 lines (26 loc) · 867 Bytes
/
connect.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
"""
Telegram client connection tool
For detailed setup, deployment and run instructions see readme.md file
Written by Maksym Trineiev
"""
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
from telethon import TelegramClient, sync
if __name__ == '__main__':
try:
client = TelegramClient(
config['Telegram']['SESSION'],
config['Telegram']['API_ID'],
config['Telegram']['API_HASH'])
client.start()
user = client.get_me()
except Exception as e:
print(f"Can't connect to Telegram client. Reason: {str(e)}")
exit(1)
print("Client connected as "\
f"{user.first_name} {user.last_name}\n"\
f"Username: {user.username}\n"\
f"Phone: +{user.phone}\n"\
f"Session: {config['Telegram']['SESSION']}")
client.disconnect()