Skip to content

Commit

Permalink
use proper scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed May 24, 2024
1 parent 81083c2 commit 15bad67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
14 changes: 3 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# pylint: disable=unused-argument
import asyncio
import calendar
import logging
import os
from datetime import datetime

from telebot import BotApp
from telegram import Update
Expand Down Expand Up @@ -113,21 +113,13 @@ async def about_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
)


@bot.job(time=os.getenv("HEADS_UP_TIME", "08:00"))
@bot.job(time=os.getenv("HEADS_UP_TIME", "08:00"),
days=(calendar.SUNDAY, calendar.MONDAY, calendar.TUESDAY, calendar.WEDNESDAY, calendar.THURSDAY))
async def send_lunch_headsup(context: ContextTypes.DEFAULT_TYPE, chat_id):
if datetime.today().weekday() in [4, 5]:
logging.info('today is weekend, job will be suspended')
return

order_manager.clear_orders()
await context.bot.send_message(chat_id, text="يلا يا شباب أبدأو ضيفو طلابتكم")


@bot.job(time=os.getenv("SELECTION_TIME", "09:30"), enabled=False)
async def send_lunch_selection(context: ContextTypes.DEFAULT_TYPE, chat_id):
await select_user(context, chat_id)


async def select_user(context: ContextTypes.DEFAULT_TYPE, chat_id):
users = [user for (_, user), _ in order_manager.list_orders().items()]
if users:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pytz==2024.1
requests==2.31.0
six==1.16.0
sniffio==1.3.1
telebot @ git+https://github.com/mhewedy/telebot@7baf8e4204457f62364bde0a385aed7e6cf4612c
telebot @ git+https://github.com/mhewedy/telebot@76bf72d94ee57809b68d27de1109e76309b6623e
telegram==0.0.1
tornado==6.4
tqdm==4.66.4
Expand Down

0 comments on commit 15bad67

Please sign in to comment.