Skip to content

Commit 7badcd3

Browse files
committed
Merge develop -> asyncio
2 parents adda199 + 64939e5 commit 7badcd3

78 files changed

Lines changed: 245 additions & 283 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pyrogram/api/all.py
1111
# PyCharm stuff
1212
.idea/
1313

14+
# VS Code
15+
.vscode/
16+
1417
# Byte-compiled / optimized / DLL files
1518
__pycache__/
1619
*.py[cod]
@@ -78,6 +81,7 @@ instance/
7881

7982
# Sphinx documentation
8083
docs/_build/
84+
docs/source/_build
8185

8286
# PyBuilder
8387
target/

compiler/api/compiler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ def start():
478478

479479
f.write("\n 0xbc799737: \"pyrogram.api.core.BoolFalse\",")
480480
f.write("\n 0x997275b5: \"pyrogram.api.core.BoolTrue\",")
481-
f.write("\n 0x56730bcc: \"pyrogram.api.core.Null\",")
482481
f.write("\n 0x1cb5c415: \"pyrogram.api.core.Vector\",")
483482
f.write("\n 0x73f1f8dc: \"pyrogram.api.core.MsgContainer\",")
484483
f.write("\n 0xae500895: \"pyrogram.api.core.FutureSalts\",")

docs/source/faq.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ dismissed and their IP addresses are now kept as aliases to the nearest one.
192192

193193
Thanks to `@FrayxRulez <https://t.me/tgbetachat/104921>`_ for telling about alias DCs.
194194

195-
196195
I want to migrate my account from DCX to DCY.
197196
---------------------------------------------
198197

@@ -246,9 +245,13 @@ The error in question is ``[400 PEER_ID_INVALID]``, and could mean several thing
246245

247246
- The chat id you tried to use is simply wrong, double check it.
248247
- The chat id refers to a group or channel you are not a member of.
249-
- The chat id refers to a user you have't seen yet (from contacts, groups in common, forwarded messages or private
250-
chats).
251248
- The chat id argument you passed is in form of a string; you have to convert it into an integer with ``int(chat_id)``.
249+
- The chat id refers to a user your current session haven't met yet.
250+
251+
About the last point: in order for you to meet a user and thus communicate with them, you should ask yourself how to
252+
contact people using official apps. The answer is the same for Pyrogram too and involves normal usages such as searching
253+
for usernames, meet them in a common group, have their phone contacts saved, getting a message mentioning them (either a
254+
forward or a mention in the message text).
252255

253256
UnicodeEncodeError: '<encoding>' codec can't encode …
254257
-----------------------------------------------------
@@ -258,6 +261,14 @@ shows up when you try to print something and has very little to do with Pyrogram
258261
your own terminal. To fix it, either find a way to change the encoding settings of your terminal to UTF-8 or switch to a
259262
better terminal altogether.
260263

264+
Uploading with URLs gives error WEBPAGE_CURL_FAILED
265+
---------------------------------------------------
266+
267+
When uploading media files using an URL, the server automatically tries to download the media and uploads it to the
268+
Telegram cloud. This error usually happens in case the provided URL is not publicly accessible by Telegram itself or the
269+
media exceeds 20 MB in size. In such cases, your only option is to download the media yourself and upload from your
270+
local machine.
271+
261272
My verification code expires immediately!
262273
-----------------------------------------
263274

docs/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ Welcome to Pyrogram
4545
topics/tgcrypto
4646
topics/storage-engines
4747
topics/text-formatting
48-
topics/serialize
48+
topics/serializing
4949
topics/proxy
50+
topics/scheduling
5051
topics/bots-interaction
5152
topics/mtproto-vs-botapi
5253
topics/debugging

docs/source/topics/scheduling.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
Scheduling Tasks
2+
================
3+
4+
Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is
5+
useful, for example, to send recurring messages to specific chats or users.
6+
7+
Since there's no built-in task scheduler in Pyrogram, this page will only show examples on how to integrate Pyrogram
8+
with the main Python schedule libraries such as ``schedule`` and ``apscheduler``. For more detailed information, you can
9+
visit and learn from each library documentation.
10+
11+
Using ``schedule``
12+
------------------
13+
14+
- Install with ``pip3 install schedule``
15+
- Documentation: https://schedule.readthedocs.io
16+
17+
.. code-block:: python
18+
19+
import time
20+
21+
import schedule
22+
23+
from pyrogram import Client
24+
25+
app = Client("my_account")
26+
27+
28+
def job():
29+
app.send_message("me", "Hi!")
30+
31+
32+
schedule.every(3).seconds.do(job)
33+
34+
with app:
35+
while True:
36+
schedule.run_pending()
37+
time.sleep(1)
38+
39+
40+
41+
Using ``apscheduler``
42+
---------------------
43+
44+
- Install with ``pip3 install apscheduler``
45+
- Documentation: https://apscheduler.readthedocs.io
46+
47+
.. code-block:: python
48+
49+
from apscheduler.schedulers.background import BackgroundScheduler
50+
51+
from pyrogram import Client
52+
53+
app = Client("my_account")
54+
55+
56+
def job():
57+
app.send_message("me", "Hi!")
58+
59+
60+
scheduler = BackgroundScheduler()
61+
scheduler.add_job(job, "interval", seconds=3)
62+
63+
scheduler.start()
64+
app.run()
65+
66+
``apscheduler`` does also support async code, here's an example with
67+
`Pyrogram Asyncio <https://docs.pyrogram.org/intro/install.html#asynchronous>`_:
68+
69+
.. code-block:: python
70+
71+
from apscheduler.schedulers.asyncio import AsyncIOScheduler
72+
73+
from pyrogram import Client
74+
75+
app = Client("my_account")
76+
77+
78+
async def job():
79+
await app.send_message("me", "Hi!")
80+
81+
82+
scheduler = AsyncIOScheduler()
83+
scheduler.add_job(job, "interval", seconds=3)
84+
85+
scheduler.start()
86+
app.run()
87+
File renamed without changes.

pyrogram/api/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
from importlib import import_module
2020

2121
from .all import objects
22-
from .core.tl_object import TLObject
2322

2423
for k, v in objects.items():
2524
path, name = v.rsplit(".", 1)
26-
TLObject.all[k] = getattr(import_module(path), name)
25+
objects[k] = getattr(import_module(path), name)

pyrogram/api/core/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222
from .list import List
2323
from .message import Message
2424
from .msg_container import MsgContainer
25-
from .primitives import (
26-
Bool, BoolTrue, BoolFalse, Bytes, Double,
27-
Int, Long, Int128, Int256, Null, String, Vector
28-
)
25+
from .primitives import *
2926
from .tl_object import TLObject

pyrogram/api/core/primitives/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19-
from .bool import Bool, BoolTrue, BoolFalse
19+
from .bool import Bool, BoolFalse, BoolTrue
2020
from .bytes import Bytes
2121
from .double import Double
2222
from .int import Int, Long, Int128, Int256
23-
from .null import Null
2423
from .string import String
2524
from .vector import Vector
25+
26+
__all__ = ["Bool", "BoolFalse", "BoolTrue", "Bytes", "Double", "Int", "Long", "Int128", "Int256", "String", "Vector"]

pyrogram/api/core/primitives/null.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)