Daily reminder to play

This commit is contained in:
Kellermann 2022-05-31 09:23:43 +02:00
parent f606d1e10b
commit b9341d9707

View File

@ -20,6 +20,7 @@ from db import User, session, Product, Score
CHALLENGE_READY = "0 8 * * *" CHALLENGE_READY = "0 8 * * *"
CHALLENGE_OVER = "0 22 * * *" CHALLENGE_OVER = "0 22 * * *"
USER_REMINDER = "0 19 * * *"
GET_NEW_PRODUCT = "0 0 * * *" GET_NEW_PRODUCT = "0 0 * * *"
def start_challenges(): def start_challenges():
@ -31,6 +32,8 @@ def start_challenges():
new_product_split = GET_NEW_PRODUCT.split(" ") new_product_split = GET_NEW_PRODUCT.split(" ")
reminder_split = USER_REMINDER.split(" ")
my_scheduler = BackgroundScheduler() my_scheduler = BackgroundScheduler()
# Sending the current event at the given crontags # Sending the current event at the given crontags
@ -60,12 +63,34 @@ def start_challenges():
, month= new_product_split[3]\ , month= new_product_split[3]\
, day=new_product_split[2]) , day=new_product_split[2])
my_scheduler.add_job(remind_users, 'cron'\
,day_of_week = reminder_split[4] \
, hour= reminder_split[1] \
, minute = reminder_split[0]\
, month= reminder_split[3]\
, day=reminder_split[2])
my_scheduler.start() my_scheduler.start()
time.sleep( 3600 ) time.sleep( 3600 )
my_scheduler.shutdown() my_scheduler.shutdown()
start_challenges() start_challenges()
def remind_users():
all_users = pandas.DataFrame(session.query(User.telegram_id).all())
guessed_today = False
for user in all_users:
guessed_today = False
user_guesses = session.query(Score).filter(Score.telegram_id == user).all()
for guesses in user_guesses:
if guesses.date.date() == dt.datetime.now().date():
guessed_today = True
break
if not guessed_today:
bot.send_message(chat_id=int(user), text="REMINDER: You haven't guessed today!\n"\
"There are 3 Hours left. Good Luck :)")
def set_todays_product(): def set_todays_product():
"""Get a random product from the database """Get a random product from the database