minutes
This commit is contained in:
parent
a3ded40e06
commit
0bfc217b78
@ -15,29 +15,10 @@ from helpers.ruz import ruz
|
|||||||
|
|
||||||
|
|
||||||
def process():
|
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 user in mongo.users_collection.find({"notify_minutes": {"$ne": None}, "hse_id": {"$ne": None}}):
|
||||||
for lesson in mongo.lessons_collection.find({
|
for lesson in mongo.lessons_collection.find({
|
||||||
"hse_user_id": user["hse_id"],
|
"hse_user_id": user["hse_id"],
|
||||||
"begin": {"$lte": now() + datetime.timedelta(minutes=5)},
|
"begin": {"$lte": now() + datetime.timedelta(minutes=user["notify_minutes"])},
|
||||||
"notified": False
|
"notified": False
|
||||||
}):
|
}):
|
||||||
ans = ""
|
ans = ""
|
||||||
|
@ -4,5 +4,5 @@ import zoneinfo
|
|||||||
|
|
||||||
def now():
|
def now():
|
||||||
zone = zoneinfo.ZoneInfo("Europe/Moscow")
|
zone = zoneinfo.ZoneInfo("Europe/Moscow")
|
||||||
today = datetime.datetime.now(zone)
|
today = datetime.datetime.now(zone) + datetime.timedelta(hours=3)
|
||||||
return today
|
return today
|
||||||
|
Loading…
Reference in New Issue
Block a user