From 30664b26d53bcf6ed10a6ddf79cf797b50e5afcd Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 27 Nov 2020 19:05:58 +0100 Subject: [PATCH] Remove "schedule" from docs --- docs/source/topics/scheduling.rst | 78 ++++++++++--------------------- 1 file changed, 25 insertions(+), 53 deletions(-) diff --git a/docs/source/topics/scheduling.rst b/docs/source/topics/scheduling.rst index 0776d601..f96e7b07 100644 --- a/docs/source/topics/scheduling.rst +++ b/docs/source/topics/scheduling.rst @@ -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 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 -with the main Python schedule libraries such as ``schedule`` and ``apscheduler``. For more detailed information, you can -visit and learn from each library documentation. +This page will show examples on how to integrate Pyrogram with ``apscheduler`` in both asynchronous and +non-asynchronous contexts. For more detailed information, you can visit and learn from the library documentation. .. contents:: Contents :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`` --------------------- - Install with ``pip3 install apscheduler`` - Documentation: https://apscheduler.readthedocs.io -.. 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() - -``apscheduler`` does also support async code, here's an example: +Asynchronously +^^^^^^^^^^^^^^ .. code-block:: python @@ -91,3 +42,24 @@ Using ``apscheduler`` scheduler.start() 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()