Правка поздравлеия с ДР
This commit is contained in:
+12
-8
@@ -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')} создан")
|
||||
|
||||
Reference in New Issue
Block a user