mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 05:18:10 +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)
|
- [**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_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_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)
|
- [**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)
|
- [**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)
|
- [**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"
|
"e" if sys.getfilesystemencoding() == "ascii" else "\xe8"
|
||||||
)
|
)
|
||||||
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
__license__ = "GNU Lesser General Public License v3 or later (LGPLv3+)"
|
||||||
__version__ = "0.6.2"
|
__version__ = "0.6.3"
|
||||||
|
|
||||||
from .api.errors import Error
|
from .api.errors import Error
|
||||||
from .client import ChatAction
|
from .client import ChatAction
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -53,7 +53,7 @@ class AES:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ctr_decrypt(data: bytes, key: bytes, iv: bytes, offset: int) -> bytes:
|
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
|
iv = iv[:-4] + replace
|
||||||
|
|
||||||
if is_fast:
|
if is_fast:
|
||||||
|
@ -122,8 +122,6 @@ class Session:
|
|||||||
self.is_connected = Event()
|
self.is_connected = Event()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
terms = None
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.connection.connect()
|
self.connection.connect()
|
||||||
@ -141,7 +139,7 @@ class Session:
|
|||||||
self.next_salt_thread.start()
|
self.next_salt_thread.start()
|
||||||
|
|
||||||
if not self.is_cdn:
|
if not self.is_cdn:
|
||||||
terms = self._send(
|
self._send(
|
||||||
functions.InvokeWithLayer(
|
functions.InvokeWithLayer(
|
||||||
layer,
|
layer,
|
||||||
functions.InitConnection(
|
functions.InitConnection(
|
||||||
@ -150,10 +148,10 @@ class Session:
|
|||||||
self.SYSTEM_VERSION,
|
self.SYSTEM_VERSION,
|
||||||
self.APP_VERSION,
|
self.APP_VERSION,
|
||||||
"en", "", "en",
|
"en", "", "en",
|
||||||
functions.help.GetTermsOfService(),
|
functions.help.GetConfig(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
).text
|
)
|
||||||
|
|
||||||
self.ping_thread = Thread(target=self.ping, name="PingThread")
|
self.ping_thread = Thread(target=self.ping, name="PingThread")
|
||||||
self.ping_thread.start()
|
self.ping_thread.start()
|
||||||
@ -168,8 +166,6 @@ class Session:
|
|||||||
|
|
||||||
log.debug("Session started")
|
log.debug("Session started")
|
||||||
|
|
||||||
return terms
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.is_connected.clear()
|
self.is_connected.clear()
|
||||||
|
|
||||||
@ -190,6 +186,9 @@ class Session:
|
|||||||
for i in range(self.NET_WORKERS):
|
for i in range(self.NET_WORKERS):
|
||||||
self.recv_queue.put(None)
|
self.recv_queue.put(None)
|
||||||
|
|
||||||
|
for i in self.results.values():
|
||||||
|
i.event.set()
|
||||||
|
|
||||||
log.debug("Session stopped")
|
log.debug("Session stopped")
|
||||||
|
|
||||||
def restart(self):
|
def restart(self):
|
||||||
@ -401,7 +400,7 @@ class Session:
|
|||||||
try:
|
try:
|
||||||
return self._send(data)
|
return self._send(data)
|
||||||
except (OSError, TimeoutError):
|
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
|
continue
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user