new notify

This commit is contained in:
Administrator
2023-03-30 00:53:29 +03:00
parent 7b28762c14
commit b11574c188
5 changed files with 104 additions and 5 deletions

View File

@@ -54,7 +54,8 @@ def fetch_schedule_for_user(user: User):
),
"building": element['building'],
"lecturer": element['lecturer'],
"notified": False
"notified": False,
"notified_today": False
})
saved_ids.append(result.inserted_id)
else:

View File

@@ -59,6 +59,40 @@ def process():
{"$set": {"next_daily_notify_time": user_model.next_daily_notify_time + datetime.timedelta(days=1)}}
)
for user in mongo.users_collection.find({"first_lesson_notify": {"$ne": None}, "hse_id": {"$ne": None}}):
time_now = now(UserSchema().load(user))
for lesson in mongo.lessons_collection.find({
"hse_user_id": user["hse_id"],
"begin": {"$lte": time_now + datetime.timedelta(minutes=user["first_lesson_notify"])},
"notified_today": {"$ne": True}
}).sort("begin"):
ans = f"📅 {lesson['begin'].strftime('%d.%m')}\n"
ans += f"📚 {lesson['discipline']}\n"
ans += f"🏢 {lesson['building']}, {lesson['auditorium']}\n"
ans += f"🕑 {lesson['begin'].strftime('%H:%M')} - {lesson['end'].strftime('%H:%M')}\n"
ans += f"🧑‍🏫 {(lesson['lecturer'] or 'Неизвестно')}\n"
if lesson.get('link', None):
ans += f"🔗 {lesson['link']}"
try:
mess = "Пары начутся через "
if user['first_lesson_notify'] == 30:
mess += "30 минут"
elif user['first_lesson_notify'] == 60:
mess += "1 час"
elif user['first_lesson_notify'] == 4 * 60:
mess += "4 часа"
else:
mess += "12 часов"
mess += "!\n\nТвоя первая пара:\n\n" + ans
bot.send_message(
user["chat_id"],
mess
)
except ApiTelegramException:
pass
mongo.lessons_collection.update_many({"begin": {"$gte": time_now.date(), "$lt": (time_now + datetime.timedelta(days=1)).date()}}, {"$set": {"notified_today": True}})
break
def notify():
while True: