fix time
This commit is contained in:
parent
0acdb8f5ee
commit
87342da1fc
@ -33,6 +33,7 @@ def process():
|
|||||||
except ApiTelegramException:
|
except ApiTelegramException:
|
||||||
pass
|
pass
|
||||||
mongo.lessons_collection.update_one({"_id": lesson['_id']}, {"$set": {"notified": True}})
|
mongo.lessons_collection.update_one({"_id": lesson['_id']}, {"$set": {"notified": True}})
|
||||||
|
time_now = datetime.datetime.now()
|
||||||
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
|
for user in mongo.users_collection.find({"next_daily_notify_time": {"$lte": time_now}}):
|
||||||
user_model = UserSchema().load(user)
|
user_model = UserSchema().load(user)
|
||||||
if time_now.weekday() != 6:
|
if time_now.weekday() != 6:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import logging
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
|
|
||||||
from helpers.models import User
|
from helpers.models import User
|
||||||
@ -16,9 +17,8 @@ def now(user: User):
|
|||||||
return today
|
return today
|
||||||
|
|
||||||
|
|
||||||
def get_next_daily_notify_time(user: User, time_now: datetime.datetime | None = None) -> datetime.datetime:
|
def get_next_daily_notify_time(user: User) -> datetime.datetime:
|
||||||
if time_now is None:
|
time_now = now(user)
|
||||||
time_now = now(user)
|
|
||||||
hours, minutes = map(int, user.daily_notify_time.split(":"))
|
hours, minutes = map(int, user.daily_notify_time.split(":"))
|
||||||
next_time = datetime.datetime(
|
next_time = datetime.datetime(
|
||||||
year=time_now.year,
|
year=time_now.year,
|
||||||
@ -27,9 +27,9 @@ def get_next_daily_notify_time(user: User, time_now: datetime.datetime | None =
|
|||||||
hour=hours,
|
hour=hours,
|
||||||
minute=minutes
|
minute=minutes
|
||||||
)
|
)
|
||||||
print('now time is', time_now)
|
logging.info('now time is %s', time_now)
|
||||||
print('user wants to notify at', hours, minutes)
|
logging.info('user wants to notify at %s %s', hours, minutes)
|
||||||
if time_now.hour * 60 + time_now.minute > hours * 60 + minutes:
|
if time_now.hour * 60 + time_now.minute > hours * 60 + minutes:
|
||||||
print('go to next day')
|
logging.info('go to next day')
|
||||||
next_time = next_time + datetime.timedelta(days=1)
|
next_time = next_time + datetime.timedelta(days=1)
|
||||||
return next_time
|
return next_time - datetime.timedelta(hours=campus_timdelta[user.campus])
|
||||||
|
Loading…
Reference in New Issue
Block a user