Last active
December 23, 2022 14:27
-
-
Save Eragoo/55500dff567a1bfd5b998ec3a65a7662 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from telethon import TelegramClient | |
from telethon.tl import functions | |
from telethon.tl.types import UserStatusOnline, UserStatusOffline | |
async def authorize(client): | |
is_authorized = await client.is_user_authorized() | |
if not is_authorized: | |
number = '' | |
await client.send_code_request(number) | |
code = input('Enter code: ') | |
await client.sign_up(code, 'name', 'surname') | |
async def get_user_status(user_id): | |
API_HASH = '' | |
API_ID = 0 | |
client = TelegramClient('online_status', API_ID, API_HASH) | |
await client.connect() | |
await authorize(client) | |
await client.start() | |
account = await client(functions.users.GetFullUserRequest( | |
id=user_id | |
)) | |
account_ = await client.get_entity(account.full_user.id) | |
print(account_) | |
status = account_.status | |
if isinstance(status, UserStatusOnline): | |
is_online = True | |
elif isinstance(status, UserStatusOffline): | |
is_online = False | |
else: | |
is_online = None | |
return is_online | |
if __name__ == '__main__': | |
print(asyncio.run(get_user_status('yevheniiku'))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment