-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_auth.py
More file actions
26 lines (22 loc) · 796 Bytes
/
Copy path_auth.py
File metadata and controls
26 lines (22 loc) · 796 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
import os, asyncio
from telethon import TelegramClient
# Загружаем .env
for line in open('.env'):
line=line.strip()
if '=' in line and not line.startswith('#'):
k,v=line.split('=',1)
os.environ[k]=v
api_id = int(os.environ['TELEGRAM_API_ID'])
api_hash = os.environ['TELEGRAM_API_HASH']
phone = os.environ['TELEPHONE']
async def main():
client = TelegramClient('/app/data/tg_session', api_id, api_hash)
await client.connect()
if not await client.is_user_authorized():
result = await client.send_code_request(phone)
print('CODE_SENT phone_code_hash=' + result.phone_code_hash)
else:
me = await client.get_me()
print('ALREADY_AUTH:', me.username or me.first_name)
await client.disconnect()
asyncio.run(main())