-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler.py
More file actions
69 lines (55 loc) · 1.8 KB
/
scheduler.py
File metadata and controls
69 lines (55 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import pytz
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from grupy_sanca_agenda_bot import event_extractor
from grupy_sanca_agenda_bot.utils import (
PeriodEnum,
delete_cache,
filter_events,
format_event_message,
send_message,
)
def setup_scheduler(application, loop):
scheduler = AsyncIOScheduler(timezone=pytz.timezone("America/Sao_Paulo"), event_loop=loop)
scheduler.add_job(
send_monthly_events,
"cron",
day=1,
hour=9,
args=[application],
)
scheduler.add_job(
send_weekly_events,
"cron",
day_of_week="mon",
hour=9,
args=[application],
)
scheduler.add_job(
send_today_events,
"cron",
day_of_week="mon-sun",
hour=12,
args=[application],
)
scheduler.add_job(
delete_cache,
"cron",
day_of_week="mon-sun",
hour=8,
)
scheduler.start()
async def send_monthly_events(application):
events = filter_events(await event_extractor.load_events(), period=PeriodEnum.mensal)
if events:
message = format_event_message(events, header="Eventos do Mês", description=False)
await send_message(message, application)
async def send_weekly_events(application):
events = filter_events(await event_extractor.load_events(), period=PeriodEnum.semanal)
if events:
message = format_event_message(events, header="Eventos da Semana", description=False)
await send_message(message, application)
async def send_today_events(application):
events = filter_events(await event_extractor.load_events(), period=PeriodEnum.hoje)
if events:
message = format_event_message(events, header="Eventos de Hoje", description=True)
await send_message(message, application)