-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser_init.py
27 lines (19 loc) · 937 Bytes
/
parser_init.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
import asyncio
from telethon.errors import SessionPasswordNeededError
from src.di.container import init_container
from src.infrastructure.tg.telegram_client_factory import TelegramClientFactory
async def init_parser() -> None:
container = init_container()
telegram_client_factory = await container.get(TelegramClientFactory)
telegram_client = await telegram_client_factory.get_client()
if not await telegram_client.engine.is_user_authorized():
phone = input("Enter your phone number: ")
await telegram_client.engine.send_code_request(phone=phone)
code = input("Enter the code: ")
try:
await telegram_client.engine.sign_in(phone, code)
except SessionPasswordNeededError:
password = input("Please enter your 2FA password: ")
await telegram_client.engine.sign_in(password=password)
if __name__ == "__main__":
asyncio.run(init_parser())