From 142a27f52ac910d8a5afed247c6da493c64c3993 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 22 Jun 2018 13:30:18 +0200 Subject: [PATCH] Use app.run() in the examples --- examples/callback_query_handler.py | 3 +-- examples/echo_bot.py | 3 +-- examples/get_history.py | 4 ++-- examples/get_participants.py | 4 ++-- examples/get_participants2.py | 5 ++--- examples/raw_update_handler.py | 3 +-- examples/welcome_bot.py | 3 +-- 7 files changed, 10 insertions(+), 15 deletions(-) diff --git a/examples/callback_query_handler.py b/examples/callback_query_handler.py index 6b76edd8..999c2686 100644 --- a/examples/callback_query_handler.py +++ b/examples/callback_query_handler.py @@ -34,5 +34,4 @@ def answer(client, callback_query): ) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/echo_bot.py b/examples/echo_bot.py index ed2d4df5..adda52c7 100644 --- a/examples/echo_bot.py +++ b/examples/echo_bot.py @@ -36,5 +36,4 @@ def echo(client, message): ) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/get_history.py b/examples/get_history.py index d53bed96..433d127c 100644 --- a/examples/get_history.py +++ b/examples/get_history.py @@ -24,12 +24,12 @@ from pyrogram.api.errors import FloodWait """This example shows how to retrieve the full message history of a chat""" app = Client("my_account") -app.start() - target = "me" # "me" refers to your own chat (Saved Messages) messages = [] # List that will contain all the messages of the target chat offset_id = 0 # ID of the last message of the chunk +app.start() + while True: try: m = app.get_history(target, offset_id=offset_id) diff --git a/examples/get_participants.py b/examples/get_participants.py index d10710ba..fd5257fb 100644 --- a/examples/get_participants.py +++ b/examples/get_participants.py @@ -28,13 +28,13 @@ Refer to get_participants2.py for more than 10.000 users. """ app = Client("my_account") -app.start() - target = "pyrogramchat" # Target channel/supergroup users = [] # List that will contain all the users of the target chat limit = 200 # Amount of users to retrieve for each API call offset = 0 # Offset starts at 0 +app.start() + while True: try: participants = app.send( diff --git a/examples/get_participants2.py b/examples/get_participants2.py index dfad315b..a70afb74 100644 --- a/examples/get_participants2.py +++ b/examples/get_participants2.py @@ -33,15 +33,14 @@ as some user names may not contain ascii letters at all. """ app = Client("my_account") -app.start() - target = "pyrogramchat" # Target channel/supergroup username or id users = {} # To ensure uniqueness, users will be stored in a dictionary with user_id as key limit = 200 # Amount of users to retrieve for each API call (200 is the maximum) - # "" + "0123456789" + "abcdefghijklmnopqrstuvwxyz" (as list) queries = [""] + [str(i) for i in range(10)] + list(ascii_lowercase) +app.start() + for q in queries: print("Searching for '{}'".format(q)) offset = 0 # For each query, offset restarts from 0 diff --git a/examples/raw_update_handler.py b/examples/raw_update_handler.py index eb417c24..c7195761 100644 --- a/examples/raw_update_handler.py +++ b/examples/raw_update_handler.py @@ -28,5 +28,4 @@ def raw(client, update, users, chats): print(update) -app.start() -app.idle() +app.run() # Automatically start() and idle() diff --git a/examples/welcome_bot.py b/examples/welcome_bot.py index 8e087728..5fd93293 100644 --- a/examples/welcome_bot.py +++ b/examples/welcome_bot.py @@ -49,5 +49,4 @@ def welcome(client, message): ) -app.start() -app.idle() +app.run() # Automatically start() and idle()