diff --git a/daemons/notify.py b/daemons/notify.py index fb9e320..3fd63b4 100644 --- a/daemons/notify.py +++ b/daemons/notify.py @@ -15,29 +15,10 @@ from helpers.ruz import ruz def process(): - for user in mongo.users_collection.find({"hse_id": {"$ne": None}, "next_notify_time": {"$lte": now()}}): - try: - lessons = mongo.get_today_lessons(UserSchema().load(user)) - if len(lessons) == 0: - ans = "Сегодня у тебя нет пар." - else: - ans = ruz.schedule_builder(lessons) - bot.send_message( - user['chat_id'], - "Напоминаю о занятиях сегодня!\n" + ans, - reply_markup=main_keyboard() - ) - except: - pass - hours, minutes = user['notify_daily'].split(':') - cron = croniter.croniter(f"{minutes} {hours} * * *", now()) - next_date = cron.get_next(datetime.datetime) - next_date = next_date.replace(tzinfo=pytz.timezone('Europe/Moscow')) - mongo.users_collection.update_one({"chat_id": user['chat_id']}, {"$set": {"next_notify_time": next_date}}) for user in mongo.users_collection.find({"notify_minutes": {"$ne": None}, "hse_id": {"$ne": None}}): for lesson in mongo.lessons_collection.find({ "hse_user_id": user["hse_id"], - "begin": {"$lte": now() + datetime.timedelta(minutes=5)}, + "begin": {"$lte": now() + datetime.timedelta(minutes=user["notify_minutes"])}, "notified": False }): ans = "" diff --git a/helpers/__init__.py b/helpers/__init__.py index 8e0d027..ad31bac 100644 --- a/helpers/__init__.py +++ b/helpers/__init__.py @@ -4,5 +4,5 @@ import zoneinfo def now(): zone = zoneinfo.ZoneInfo("Europe/Moscow") - today = datetime.datetime.now(zone) + today = datetime.datetime.now(zone) + datetime.timedelta(hours=3) return today