daily notify

This commit is contained in:
Administrator
2022-10-22 20:45:32 +03:00
parent f7d181f144
commit 7b8168e297
6 changed files with 115 additions and 3 deletions

View File

@@ -4,8 +4,10 @@ from time import sleep
from telebot.apihelper import ApiTelegramException
from daemons.bot import bot
from helpers import now
from helpers import now, get_next_daily_notify_time
from helpers.models import UserSchema
from helpers.mongo import mongo
from helpers.ruz import ruz
def process():
@@ -28,6 +30,27 @@ def process():
except ApiTelegramException:
pass
mongo.lessons_collection.update_one({"_id": lesson['_id']}, {"$set": {"notified": True}})
time_now = now()
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
user_model = UserSchema().load(user)
if time_now.weekday() == 6:
mongo.users_collection.update_one(
{"chat_id": user["chat_id"]},
{"$set": {"next_daily_notify_time": get_next_daily_notify_time(user_model, time_now)}}
)
else:
lessons = mongo.get_today_lessons(user_model)
if len(lessons) == 0:
text = "Сегодня у тебя нет пар."
else:
text = ruz.schedule_builder(lessons)
try:
bot.send_message(
user["chat_id"],
"Уведомляю о занятиях!\n" + text
)
except:
pass
def notify():