Правка поздравлеия с ДР

This commit is contained in:
2026-01-03 11:12:55 +03:00
parent 9afa7e8baf
commit 0e46a1ca7f
3 changed files with 32 additions and 8 deletions
+12 -8
View File
@@ -54,29 +54,33 @@ def handle_vk_birthdate():
def is_leap_year(year: int) -> bool:
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
# Основное условие: совпадение дня и месяца
conditions = [
# условия ТОЛЬКО по дате
date_conditions = [
and_(
func.strftime("%d", UsersBirthdate.birthdate) == day,
func.strftime("%m", UsersBirthdate.birthdate) == month,
)
]
# Если 28 февраля и год НЕ високосный — добавляем родившихся 29.02
# 29 февраля для невисокосного года
if today.month == 2 and today.day == 28 and not is_leap_year(today.year):
conditions.append(
date_conditions.append(
and_(
func.strftime("%d", UsersBirthdate.birthdate) == "29",
func.strftime("%m", UsersBirthdate.birthdate) == "02",
)
)
conditions.append(UsersBirthdate.enabled == True)
birthdayUsers = UsersBirthdate.query.filter(or_(*conditions)).all()
birthdayUsers = UsersBirthdate.query.filter(
UsersBirthdate.enabled.is_(True),
or_(*date_conditions),
).all()
if not birthdayUsers:
logger.info("Нет пользователей с днем рождения")
logger.info(f"Нет пользователей с днем рождения {day}.{month}")
return
else:
logger.info(f"Найдено {len(birthdayUsers)} пользователей с днем рождения")
vkApi = VkAPI.query.first()
if not vkApi:
@@ -95,7 +99,7 @@ def handle_vk_birthdate():
owner_id=-vkApi.group_id,
from_group=1,
message=user.congratulations.strip(),
attachments=user.photo_link,
attachments=user.photo_link.replace("https://vk.com/", ""),
)
logger.info(f"Пост #{new_post.get('post_id')} создан")