File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed
Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ Welcome to Pyrogram
4040 topics/more-on-updates
4141 topics/config-file
4242 topics/smart-plugins
43+ topics/scheduling
4344 topics/auto-auth
4445 topics/session-settings
4546 topics/tgcrypto
Original file line number Diff line number Diff line change 1+ Scheduling tasks
2+ ================
3+
4+ Pyrogram itself as Telegram MTProto API Framework contains only stuff
5+ related to Telegram. Scheduling is out of it's scope.
6+
7+ But it is easy to integrate pyrogram with your favourite scheduler.
8+
9+ schedule
10+ --------
11+
12+ Note that schedule is not suitable for async version of pyrogram.
13+
14+ .. code-block :: python
15+
16+ import time
17+ import schedule
18+
19+
20+ def job ():
21+ app.send_message(" me" , " Hi!" )
22+
23+
24+ schedule.every(10 ).minutes.do(job)
25+ schedule.every().hour.do(job)
26+ schedule.every().day.at(" 10:30" ).do(job)
27+ schedule.every(5 ).to(10 ).minutes.do(job)
28+ schedule.every().monday.do(job)
29+ schedule.every().wednesday.at(" 13:15" ).do(job)
30+ schedule.every().minute.at(" :17" ).do(job)
31+
32+ with app:
33+ while True :
34+ schedule.run_pending()
35+ time.sleep(1 )
36+
37+
38+ apscheduler
39+ -----------
40+
41+ .. code-block :: python
42+
43+ import time
44+ from apscheduler.schedulers.background import BackgroundScheduler
45+
46+
47+ def job ():
48+ app.send_message(" me" , " Hi!" )
49+
50+
51+ scheduler = BackgroundScheduler()
52+ scheduler.add_job(job, ' interval' , seconds = 3 )
53+
54+ scheduler.start()
55+ app.run()
56+
57+ Apscheduler supports async version of pyrogram too, here is async example:
58+
59+ .. code-block :: python
60+
61+ from apscheduler.schedulers.asyncio import AsyncIOScheduler
62+
63+
64+ async def job ():
65+ await app.send_message(" me" , " Hi!" )
66+
67+
68+ scheduler = AsyncIOScheduler()
69+ scheduler.add_job(job, ' interval' , seconds = 3 )
70+
71+ scheduler.start()
72+ app.run()
73+
You can’t perform that action at this time.
0 commit comments