und der Telegramm -API. < /P>
Code: Select all
from telethon import TelegramClient
from telethon.tl.types import UserStatusOnline
from datetime import datetime
from time import sleep
API_ID = 12345678
API_HASH = '123456789'
USERNAMES = [
'your_username'
]
PAIRS = [
]
TRACK_FREQUENCY = 5
client = TelegramClient('bot', API_ID, API_HASH)
async def main():
while True:
online = []
offline = []
for i in USERNAMES:
entity = await client.get_entity(i)
name = entity.first_name + ' ' + entity.last_name
if isinstance(entity.status, UserStatusOnline):
# print if user tracked is online
print('[' + datetime.now().isoformat() + ']: ' + name + ' в онлайне!')
online.append(entity.username)
else:
offline.append(entity.username)
for u in PAIRS:
# check if both users in the given pair are online right now
if u[0] in online and u[1] in online:
print('[' + datetime.now().isoformat() + ']: ' + u[0] + ' и ' + u[1] + ' оба сейчас находятся в онлайне!')
elif u[0] in offline and u[1] in offline:
print('[' + datetime.now().isoformat() + ']: ' + u[0] + ' и ' + u[1] + ' оба сейчас находятся в офлайне!')
sleep(TRACK_FREQUENCY)
if __name__ == "__main__":
print("Трекер начал работу...")
client.start()
print("Трекер успешно подключился к Telegram'у!")
with client:
client.loop.run_until_complete(main())
< /code>
Die ID und Hash sind absichtlich versteckt. Sobald ich den Code ausführte, erscheint ein Fehler: < /p>
Traceback (most recent call last):
File "/workspaces/TG_Online_Tracker1/main.py", line 29, in
client = TelegramClient('bot', API_ID, API_HASH)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/codespace/.local/lib/python3.12/site-packages/telethon/client/telegrambaseclient.py", line 302, in __init__
self._sender = MTProtoSender(
^^^^^^^^^^^^^^
File "/home/codespace/.local/lib/python3.12/site-packages/telethon/network/mtprotosender.py", line 58, in __init__
self._connect_lock = asyncio.Lock(loop=loop)
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Lock.__init__() got an unexpected keyword argument 'loop'