fixed date check

This commit is contained in:
Alexander Karpov 2023-05-28 18:05:38 +03:00
parent 097c39b494
commit 35a9078d22

View File

@ -11,7 +11,6 @@
from passfinder.events.services import get_position_weather from passfinder.events.services import get_position_weather
weathers_labels = { weathers_labels = {
"drizzle": "морось",
"light-rain": "небольшой дождь", "light-rain": "небольшой дождь",
"rain": "дождь", "rain": "дождь",
"moderate-rain": "дождь", "moderate-rain": "дождь",
@ -34,26 +33,29 @@ def check_temperature():
for route in UserRoute.objects.filter( for route in UserRoute.objects.filter(
dates__date__gte=now().date(), dates__date__lte=now().date() + timedelta(days=3) dates__date__gte=now().date(), dates__date__lte=now().date() + timedelta(days=3)
): ):
points = route.dates.objects.get(date=now().date()).points.all()
cities = points.values_list("city_id").distinct()
alerts = [] alerts = []
for city in cities: for i in range(3):
if city: date = now().date() + timedelta(days=i)
city = City.objects.get(oid=city) points = route.dates.objects.get(date=date).points.all()
if city in cities_temp: cities = points.values_list("city_id").distinct()
weather_conditions = cities_temp[city] for city in cities:
else: if city:
weather_conditions = get_position_weather(city.lat, city.lon) city = City.objects.get(oid=city)
weather_conditions = [ if city in cities_temp:
(parse_date(x[0]), x[1]) for x in weather_conditions weather_conditions = cities_temp[city]
] else:
cities_temp[city] = weather_conditions weather_conditions = get_position_weather(city.lat, city.lon)
weather_conditions = dict(
for date, weather in weather_conditions: [(parse_date(x[0]), x[1]) for x in weather_conditions]
if weather in weathers_labels:
alerts.append(
f"В городе {city.title} {date.strftime('%d.%m.%Y')} предстоит {weathers_labels[weather]}"
) )
cities_temp[city] = weather_conditions
if date in weather_conditions:
weather = weather_conditions[date]
if weather in weathers_labels:
alerts.append(
f"В городе {city.title} {date.strftime('%d.%m.%Y')} предстоит {weathers_labels[weather]}"
)
if alerts: if alerts:
context = { context = {
"user": route.user, "user": route.user,