2
0
mirror of https://github.com/LonamiWebs/Telethon synced 2025-08-22 09:57:32 +00:00
telethon/telethon_examples/print_updates.py

37 lines
836 B
Python
Raw Normal View History

#!/usr/bin/env python3
# A simple script to print all updates received
2018-05-24 10:58:42 +02:00
#
# NOTE: To run this script you MUST have 'TG_API_ID' and 'TG_API_HASH' in
# your environment variables. This is a good way to use these private
# values. See https://superuser.com/q/284342.
from os import environ
2018-02-16 21:02:47 +01:00
from telethon import TelegramClient
2018-02-16 21:02:47 +01:00
client = TelegramClient(
environ.get('TG_SESSION', 'session'),
environ['TG_API_ID'],
environ['TG_API_HASH'],
proxy=None
)
2018-02-16 21:02:47 +01:00
async def update_handler(update):
print(update)
2018-02-16 21:02:47 +01:00
client.add_event_handler(update_handler)
'''You could also have used the @client.on(...) syntax:
from telethon import events
@client.on(events.Raw)
2018-06-24 12:04:23 +02:00
async def update_handler(update):
print(update)
'''
2018-02-16 21:02:47 +01:00
with client.start():
print('(Press Ctrl+C to stop this)')
client.run_until_disconnected()