Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
feat: cronjob
Browse files Browse the repository at this point in the history
  • Loading branch information
TatarinAlba committed Nov 23, 2024
1 parent 3d44fcc commit 6495bdb
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions backend/src/api/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import json
from contextlib import asynccontextmanager
from datetime import UTC, datetime

from beanie import init_beanie
from fastapi import FastAPI
Expand Down Expand Up @@ -52,22 +53,28 @@ async def push_notification():
for notification in notifications:
sent_notification_number = len(notification.event_dates)
for start_date in notification.event_dates:
days_before = 4
# if (start_date - datetime.now(UTC)).days == 30:
# days_before = 30
# elif (start_date - datetime.now(UTC)).days == 7:
# days_before = 7
# elif (start_date - datetime.now(UTC)).days == 1:
# days_before = 1
# sent_notification_number -= 1
# elif (start_date - datetime.now(UTC)).days < 0:
# sent_notification_number -= 1
days_before = None
if (start_date - datetime.now(UTC)).days == 30:
days_before = 30
elif (start_date - datetime.now(UTC)).days == 7:
days_before = 7
elif (start_date - datetime.now(UTC)).days == 1:
days_before = 1
sent_notification_number -= 1
elif (start_date - datetime.now(UTC)).days < 0:
sent_notification_number -= 1
if days_before is not None:
outMsg: str
if notification.sport_id is not None:
outMsg = f'«Через {days_before} дней соревнование по виду спорта "{notification.sport_title}"'
if days_before == 1:
outMsg = f'Через {days_before} день соревнование по виду спорта "{notification.sport_title}"'
else:
outMsg = f'Через {days_before} дней соревнование по виду спорта "{notification.sport_title}"'
elif notification.event_id is not None:
outMsg = f'«Через {days_before} дней соревнование "{notification.event_title}" по виду спорта "{notification.sport_title}"'
if days_before == 1:
outMsg = f'Через {days_before} день соревнование "{notification.event_title}" по виду спорта "{notification.sport_title}"'
else:
outMsg = f'Через {days_before} дней соревнование "{notification.event_title}" по виду спорта "{notification.sport_title}"'
try:
webpush(
subscription_info=notification.subscription_info,
Expand Down

0 comments on commit 6495bdb

Please sign in to comment.