Remove "schedule" from docs
This commit is contained in:
parent
ce729fa1e3
commit
30664b26d5
@ -4,9 +4,8 @@ Scheduling Tasks
|
|||||||
Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is
|
Scheduling tasks means executing one or more functions periodically at pre-defined intervals or after a delay. This is
|
||||||
useful, for example, to send recurring messages to specific chats or users.
|
useful, for example, to send recurring messages to specific chats or users.
|
||||||
|
|
||||||
Since there's no built-in task scheduler in Pyrogram, this page will only show examples on how to integrate Pyrogram
|
This page will show examples on how to integrate Pyrogram with ``apscheduler`` in both asynchronous and
|
||||||
with the main Python schedule libraries such as ``schedule`` and ``apscheduler``. For more detailed information, you can
|
non-asynchronous contexts. For more detailed information, you can visit and learn from the library documentation.
|
||||||
visit and learn from each library documentation.
|
|
||||||
|
|
||||||
.. contents:: Contents
|
.. contents:: Contents
|
||||||
:backlinks: none
|
:backlinks: none
|
||||||
@ -15,62 +14,14 @@ visit and learn from each library documentation.
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
Using ``schedule``
|
|
||||||
------------------
|
|
||||||
|
|
||||||
- Install with ``pip3 install schedule``
|
|
||||||
- Documentation: https://schedule.readthedocs.io
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
import time
|
|
||||||
|
|
||||||
import schedule
|
|
||||||
|
|
||||||
from pyrogram import Client
|
|
||||||
|
|
||||||
app = Client("my_account")
|
|
||||||
|
|
||||||
|
|
||||||
def job():
|
|
||||||
app.send_message("me", "Hi!")
|
|
||||||
|
|
||||||
|
|
||||||
schedule.every(3).seconds.do(job)
|
|
||||||
|
|
||||||
with app:
|
|
||||||
while True:
|
|
||||||
schedule.run_pending()
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Using ``apscheduler``
|
Using ``apscheduler``
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
- Install with ``pip3 install apscheduler``
|
- Install with ``pip3 install apscheduler``
|
||||||
- Documentation: https://apscheduler.readthedocs.io
|
- Documentation: https://apscheduler.readthedocs.io
|
||||||
|
|
||||||
.. code-block:: python
|
Asynchronously
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
|
||||||
|
|
||||||
from pyrogram import Client
|
|
||||||
|
|
||||||
app = Client("my_account")
|
|
||||||
|
|
||||||
|
|
||||||
def job():
|
|
||||||
app.send_message("me", "Hi!")
|
|
||||||
|
|
||||||
|
|
||||||
scheduler = BackgroundScheduler()
|
|
||||||
scheduler.add_job(job, "interval", seconds=3)
|
|
||||||
|
|
||||||
scheduler.start()
|
|
||||||
app.run()
|
|
||||||
|
|
||||||
``apscheduler`` does also support async code, here's an example:
|
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
@ -91,3 +42,24 @@ Using ``apscheduler``
|
|||||||
scheduler.start()
|
scheduler.start()
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
Non-Asynchronously
|
||||||
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
|
|
||||||
|
from pyrogram import Client
|
||||||
|
|
||||||
|
app = Client("my_account")
|
||||||
|
|
||||||
|
|
||||||
|
def job():
|
||||||
|
app.send_message("me", "Hi!")
|
||||||
|
|
||||||
|
|
||||||
|
scheduler = BackgroundScheduler()
|
||||||
|
scheduler.add_job(job, "interval", seconds=3)
|
||||||
|
|
||||||
|
scheduler.start()
|
||||||
|
app.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user