This commit is contained in:
Administrator 2022-10-21 23:03:35 +03:00
parent a3ded40e06
commit 0bfc217b78
2 changed files with 2 additions and 21 deletions

View File

@ -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 = ""

View File

@ -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