diff --git a/backend/services/feed_service.py b/backend/services/feed_service.py index 245ad1b..c7ff345 100644 --- a/backend/services/feed_service.py +++ b/backend/services/feed_service.py @@ -74,6 +74,7 @@ _CATEGORY_META = {ArticleCategory.SEASON.value: "계절 소식", ArticleCategory _FEED_TTL_MAX = 3600 _PARTIAL_TTL = 60 _SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용 +_NIGHT_AFTER_SUNSET = timedelta(hours=1) # 해 지고 이만큼 지나면 밤 _RAIN_PROB = 40 _UV_SHOW = 3 # 자외선 포스트: 오늘 가장 셀 때 '보통' 이상이면 띄운다 _HERO_RAIN_PROB = 60 # 히어로 '오늘 비': 오늘 남은 칸 중 비 형태가 있거나 확률이 이만큼 넘는 첫 칸 @@ -140,11 +141,11 @@ def feed_day(now: datetime) -> date: def slot_of(now: datetime, sunset_at: datetime) -> str: - """아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–21 · 밤 21–05.""" + """아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다.""" h = now.hour if 5 <= h < 11: return "morning" - if 11 <= h < 21: + if h >= 11 and now < sunset_at + _NIGHT_AFTER_SUNSET: return "day" if now < sunset_at - timedelta(hours=2) else "evening" return "night" @@ -154,7 +155,7 @@ def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int: day = now.date() at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731 sunset = sunset_at.astimezone(KST) - changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, at(day, 21), + changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, sunset + _NIGHT_AFTER_SUNSET, at(day + timedelta(days=1), _FEED_DAY_START), next_vilage_available(now)] air = now.replace(minute=20, second=0, microsecond=0) changes.append(air if air > now else air + timedelta(hours=1)) diff --git a/backend/tests/test_feed.py b/backend/tests/test_feed.py index d2daea5..ff47a6f 100644 --- a/backend/tests/test_feed.py +++ b/backend/tests/test_feed.py @@ -100,8 +100,11 @@ def test_slot_follows_sunset(): sunset = datetime(2026, 10, 2, 18, 10, tzinfo=KST) at = lambda h, m=0: datetime(2026, 10, 2, h, m, tzinfo=KST) # noqa: E731 - assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 9), (16, 10), (20, 59), (21, 0))] == [ - "night", "morning", "day", "day", "evening", "evening", "night"] + assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 9), (16, 10), (19, 9), (19, 10), (23, 0))] == [ + "night", "morning", "day", "day", "evening", "evening", "night", "night"] + summer = datetime(2026, 6, 21, 19, 57, tzinfo=KST) + assert slot_of(datetime(2026, 6, 21, 20, 30, tzinfo=KST), summer) == "evening" + assert slot_of(datetime(2026, 6, 21, 20, 57, tzinfo=KST), summer) == "night" def test_arrange_orders_by_slot_and_keeps_same_types_apart(): diff --git a/docs/피드_기획.html b/docs/피드_기획.html index 1ed63bc..4c6816c 100644 --- a/docs/피드_기획.html +++ b/docs/피드_기획.html @@ -184,8 +184,8 @@ td .note{display:block;color:var(--muted);font-size:12px;margin-top:3px;line-hei
같은 종류 카드는 붙이지 않습니다(확정). 각 3장 사이에는 다른 카드가 하나씩 끼어듭니다.
조건이 안 맞는 카드는 아예 빼고, 빈 카드나 "오늘은 없어요" 카드는 만들지 않습니다.예외: 노을은 흐린 날에도 한 줄로 남깁니다(확정).
좋아요·댓글은 카드에 붙고, 전국 사용자가 같이 봅니다. 순서가 바뀌어도 같은 카드면 좋아요가 이어집니다.
시간대가 바뀌는 순간(05·11·16·21시)과 일몰 시각, 예보 갱신 때 피드가 새로 짜입니다.앞에서 문제가 됐던 "새 칸이 늦게 보이는 문제"가 생기지 않습니다.
시간대가 바뀌는 순간(05·11시, 일몰 2시간 전·일몰 1시간 뒤)과 일몰 시각, 예보 갱신 때 피드가 새로 짜입니다.앞에서 문제가 됐던 "새 칸이 늦게 보이는 문제"가 생기지 않습니다.
카드마다 보낼 문구가 있고, 보내면 카드 그대로 이미지+링크로 갑니다(확정).
UI는 따로 고민하지 않고 인스타그램·페이스북 방식을 그대로 따릅니다(확정, 10/2).
지역은 날씨를 가져오는 시군구 단위 그대로입니다. 수원시 장안구 같은 일반구도 따로 봅니다(확정, 10/2, 256곳).