mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Merge branch 'master' into docs
This commit is contained in:
commit
a09b99b8df
@ -8,6 +8,7 @@ you have to change are the target chats (username, id) and file paths for sendin
|
||||
- [**hello_world.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/hello_world.py)
|
||||
- [**get_history.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_history.py)
|
||||
- [**get_participants.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_participants.py)
|
||||
- [**get_participants2.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_participants2.py)
|
||||
- [**inline_bots.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/inline_bots.py)
|
||||
- [**updates.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/updates.py)
|
||||
- [**simple_echo.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/simple_echo.py)
|
||||
|
63
examples/get_participants2.py
Normal file
63
examples/get_participants2.py
Normal file
@ -0,0 +1,63 @@
|
||||
import time
|
||||
from string import ascii_lowercase
|
||||
|
||||
from pyrogram import Client
|
||||
from pyrogram.api import functions, types
|
||||
from pyrogram.api.errors import FloodWait
|
||||
|
||||
"""
|
||||
This is an improved version of get_participants.py
|
||||
|
||||
Since Telegram will return at most 10.000 users for a single query, this script
|
||||
repeats the search using numbers ("0" to "9") and all the available ascii letters ("a" to "z").
|
||||
|
||||
This can be further improved by also searching for non-ascii characters (e.g.: Japanese script),
|
||||
as some user names may not contain ascii letters at all.
|
||||
"""
|
||||
|
||||
client = Client("example")
|
||||
client.start()
|
||||
|
||||
target = "username" # 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)
|
||||
|
||||
for q in queries:
|
||||
print("Searching for '{}'".format(q))
|
||||
offset = 0 # For each query, offset restarts from 0
|
||||
|
||||
while True:
|
||||
try:
|
||||
participants = client.send(
|
||||
functions.channels.GetParticipants(
|
||||
channel=client.resolve_peer(target),
|
||||
filter=types.ChannelParticipantsSearch(q),
|
||||
offset=offset,
|
||||
limit=limit,
|
||||
hash=0
|
||||
)
|
||||
)
|
||||
except FloodWait as e:
|
||||
# Very large chats could trigger FloodWait.
|
||||
# When happens, wait X seconds before continuing
|
||||
print("Flood wait: {} seconds".format(e.x))
|
||||
time.sleep(e.x)
|
||||
continue
|
||||
|
||||
if not participants.participants:
|
||||
print("Done searching for '{}'".format(q))
|
||||
print()
|
||||
break # No more participants left
|
||||
|
||||
# User information are stored in the participants.users list.
|
||||
# Add those users to the dictionary
|
||||
users.update({i.id: i for i in participants.users})
|
||||
|
||||
offset += len(participants.participants)
|
||||
|
||||
print("Total users: {}".format(len(users)))
|
||||
|
||||
client.stop()
|
@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance
|
||||
"e" if sys.getfilesystemencoding() == "ascii" else "\xe8"
|
||||
)
|
||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||
__version__ = "0.6.2"
|
||||
__version__ = "0.6.3"
|
||||
|
||||
from .api.errors import Error
|
||||
from .client import ChatAction
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -53,7 +53,7 @@ class AES:
|
||||
|
||||
@staticmethod
|
||||
def ctr_decrypt(data: bytes, key: bytes, iv: bytes, offset: int) -> bytes:
|
||||
replace = int.to_bytes(offset // 16, byteorder="big", length=4)
|
||||
replace = int.to_bytes(offset // 16, 4, "big")
|
||||
iv = iv[:-4] + replace
|
||||
|
||||
if is_fast:
|
||||
|
@ -122,8 +122,6 @@ class Session:
|
||||
self.is_connected = Event()
|
||||
|
||||
def start(self):
|
||||
terms = None
|
||||
|
||||
while True:
|
||||
try:
|
||||
self.connection.connect()
|
||||
@ -141,7 +139,7 @@ class Session:
|
||||
self.next_salt_thread.start()
|
||||
|
||||
if not self.is_cdn:
|
||||
terms = self._send(
|
||||
self._send(
|
||||
functions.InvokeWithLayer(
|
||||
layer,
|
||||
functions.InitConnection(
|
||||
@ -150,10 +148,10 @@ class Session:
|
||||
self.SYSTEM_VERSION,
|
||||
self.APP_VERSION,
|
||||
"en", "", "en",
|
||||
functions.help.GetTermsOfService(),
|
||||
functions.help.GetConfig(),
|
||||
)
|
||||
)
|
||||
).text
|
||||
)
|
||||
|
||||
self.ping_thread = Thread(target=self.ping, name="PingThread")
|
||||
self.ping_thread.start()
|
||||
@ -168,8 +166,6 @@ class Session:
|
||||
|
||||
log.debug("Session started")
|
||||
|
||||
return terms
|
||||
|
||||
def stop(self):
|
||||
self.is_connected.clear()
|
||||
|
||||
@ -190,6 +186,9 @@ class Session:
|
||||
for i in range(self.NET_WORKERS):
|
||||
self.recv_queue.put(None)
|
||||
|
||||
for i in self.results.values():
|
||||
i.event.set()
|
||||
|
||||
log.debug("Session stopped")
|
||||
|
||||
def restart(self):
|
||||
@ -401,7 +400,7 @@ class Session:
|
||||
try:
|
||||
return self._send(data)
|
||||
except (OSError, TimeoutError):
|
||||
log.warning("Retrying {}".format(type(data)))
|
||||
(log.warning if i > 0 else log.info)("{}: {} Retrying {}".format(i, datetime.now(), type(data)))
|
||||
continue
|
||||
else:
|
||||
return None
|
||||
|
Loading…
x
Reference in New Issue
Block a user