Код: Выделить всё
from telethon import TelegramClient, events, sync
from telethon.errors import SessionPasswordNeededError
import time
# Setting configuration values
api_id = 'my api id'
api_hash ='my api hash'
phone = '+my phone number'
username = 'my username'
# Create the client and connect
client = TelegramClient(username, api_id, api_hash)
client.start()
print("Client Created")
# Ensure you're authorized
if not client.is_user_authorized():
client.send_code_request(phone)
try:
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError:
client.sign_in(password=input('Password: '))
new = '#'
old = 'xd'
async def main():
limit = 1
async for message in client.iter_messages('channel sample', limit):
new = (message.text)
while True:
with client:
client.loop.run_until_complete(main())
if new != old:
old = new
print(old)
time.sleep(5)
Подробнее здесь: https://stackoverflow.com/questions/641 ... s-variable
Мобильная версия