From e0802d1a2d830c0c859622dd5c9e88b31f03db27 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 25 Nov 2017 18:47:41 +0100 Subject: [PATCH] Update README.rst to show asyncio code (#456) --- README.rst | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 21e76aca..f68f6f3e 100755 --- a/README.rst +++ b/README.rst @@ -29,26 +29,30 @@ Creating a client phone = '+34600000000' client = TelegramClient('session_name', api_id, api_hash) - client.connect() - - # If you already have a previous 'session_name.session' file, skip this. - client.sign_in(phone=phone) - me = client.sign_in(code=77777) # Put whatever code you received here. + async def main(): + await client.connect() + # Skip this if you already have a previous 'session_name.session' file + await client.sign_in(phone_number) + me = await client.sign_in(code=input('Code: ')) Doing stuff ----------- +Note that this assumes you're inside an "async def" method. Check out the +`Python documentation `_ +if you're new with ``asyncio``. + .. code:: python print(me.stringify()) - client.send_message('username', 'Hello! Talking to you from Telethon') - client.send_file('username', '/home/myself/Pictures/holidays.jpg') + await client.send_message('username', 'Hello! Talking to you from Telethon') + await client.send_file('username', '/home/myself/Pictures/holidays.jpg') - client.download_profile_photo(me) - total, messages, senders = client.get_message_history('username') - client.download_media(messages[0]) + await client.download_profile_photo(me) + total, messages, senders = await client.get_message_history('username') + await client.download_media(messages[0]) Next steps @@ -57,4 +61,6 @@ Next steps Do you like how Telethon looks? Check the `wiki over GitHub `_ for a more in-depth explanation, with examples, troubleshooting issues, and more -useful information. +useful information. Note that the examples there are written for the threaded +version, not the one using asyncio. However, you just need to await every +remote call.