From 2621db0450461ef14152751acdfaa3926ddd939a Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 13 Oct 2026 09:59:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=AF=B8=EC=84=B8=EB=A8=BC=EC=A7=80=20?= =?UTF-8?q?=ED=8F=AC=EC=8A=A4=ED=8A=B8=20=E2=80=94=20=EB=B9=84=20=EC=98=A4?= =?UTF-8?q?=EB=8A=94=EB=8D=B0=20'=EC=B0=BD=EB=AC=B8=20=ED=99=9C=EC=A7=9D?= =?UTF-8?q?=20=EC=97=B4=EC=96=B4=EB=8F=84=20=EB=8F=BC=EC=9A=94'=EB=9D=BC?= =?UTF-8?q?=EB=8D=98=20=EA=B2=83,=20=EB=B9=84=20=EC=98=A4=EB=A9=B4=20'?= =?UTF-8?q?=EC=B0=BD=EB=AC=B8=EC=9D=80=20=EB=8B=AB=EC=95=84=20=EB=91=AC?= =?UTF-8?q?=EC=9A=94'.=20=EC=88=98=EC=B9=98(=E3=8E=8D/=E3=8E=A5)=20?= =?UTF-8?q?=EB=8C=80=EC=8B=A0=20=EB=93=B1=EA=B8=89=EB=A7=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/services/feed_service.py | 8 +++++--- backend/tests/test_feed.py | 11 +++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/backend/services/feed_service.py b/backend/services/feed_service.py index 6596643..6dbdc8c 100644 --- a/backend/services/feed_service.py +++ b/backend/services/feed_service.py @@ -117,6 +117,7 @@ _AIR_LINE = { AirGrade.BAD: ("공기가 탁해요,\n마스크 챙겨요", "😷 마스크 챙겨!"), AirGrade.VERY_BAD: ("공기가 많이 탁해요,\n바깥은 짧게", "😷 오늘은 실내로!"), } +_AIR_RAIN_LINE = ("공기는 맑은데 비가 와요,\n창문은 닫아 둬요", "☔ 창문은 닫아 둬!") # 맑음·보통인데 지금~2시간 안에 비 _AIR_ADVICE = { AirGrade.BAD: "KF80 마스크 쓰고, 오래 뛰는 바깥 운동은 줄여요", AirGrade.VERY_BAD: "외출은 줄이고 창문은 닫아 둬요. 나가면 KF94 마스크", @@ -645,11 +646,12 @@ class FeedService: return None worst = max(g for _, _, g in values) label = AIR_GRADE_LABEL[worst] - rows = [Row(label=name, value=f"{v}㎍/㎥ · {AIR_GRADE_LABEL[g]}") for name, v, g in values] + rows = [Row(label=name, value=AIR_GRADE_LABEL[g]) for name, _, g in values] if worst in _AIR_ADVICE: rows.append(Row(label="이렇게 해요", value=_AIR_ADVICE[worst])) - line, tail = _AIR_LINE[worst] - icon = "vent" if worst <= AirGrade.NORMAL else "cloud" + raining = worst <= AirGrade.NORMAL and c.now_w.will_rain_2h + line, tail = _AIR_RAIN_LINE if raining else _AIR_LINE[worst] + icon = "umbrella" if raining else "vent" if worst <= AirGrade.NORMAL else "cloud" return PostData(**base, title=f"미세먼지 {label}", icon=icon, caption=f"{air.station_name} 측정소 · {air.measured_at.astimezone(KST).hour}시 기준", slides=[RowsSlide(kind="rows", eyebrow=f"지금 공기 · {c.region.short_name}", line=line, icon=icon, rows=rows)], share_messages=[f"{c.region.short_name} 지금 미세먼지 {label} {tail}"]) diff --git a/backend/tests/test_feed.py b/backend/tests/test_feed.py index 826fd62..78cb188 100644 --- a/backend/tests/test_feed.py +++ b/backend/tests/test_feed.py @@ -72,7 +72,7 @@ async def test_feed_assembles_hero_stories_posts_and_bands(offline): assert body["bands"]["events"][0]["image_credit"] == "ⓒ한국관광공사" assert "미세먼지" not in weather["caption"] air = next(p for p in body["posts"] if p["post_type"] == PostType.AIR.value) - assert [(r["label"], r["value"]) for r in air["slides"][0]["rows"]] == [("초미세먼지", "10㎍/㎥ · 좋음"), ("미세먼지", "20㎍/㎥ · 좋음")] + assert [(r["label"], r["value"]) for r in air["slides"][0]["rows"]] == [("초미세먼지", "좋음"), ("미세먼지", "좋음")] event = next(p for p in body["posts"] if p["post_type"] == PostType.EVENT.value) assert event["slides"][0]["eyebrow"].startswith("가까운 행사 · ") @@ -275,7 +275,7 @@ def test_text_helpers_short_day_and_compass(): assert compass(263) == "서" and compass(247) == "서남서" -def _air(pm25, pm10, measured_hours_ago=0): +def _air(pm25, pm10, measured_hours_ago=0, rain=False): from datetime import datetime from types import SimpleNamespace @@ -285,7 +285,7 @@ def _air(pm25, pm10, measured_hours_ago=0): now = datetime(2026, 10, 2, 9, 30, tzinfo=KST) air = None if pm25 is None and pm10 is None else SimpleNamespace( station_name="테스트", pm25=pm25, pm10=pm10, measured_at=now.replace(minute=0) - timedelta(hours=measured_hours_ago)) - ctx = SimpleNamespace(now=now, region=SimpleNamespace(short_name="종로구"), now_w=SimpleNamespace(air=air)) + ctx = SimpleNamespace(now=now, region=SimpleNamespace(short_name="종로구"), now_w=SimpleNamespace(air=air, will_rain_2h=rain)) return FeedService._air(None, _base() | {"post_type": PostType.AIR}, ctx) @@ -294,8 +294,11 @@ def test_air_post_shows_both_values_and_advice_only_when_bad(): assert [r.label for r in good.slides[0].rows] == ["초미세먼지", "미세먼지"] and good.title == "미세먼지 좋음" bad = _air(40, 60) assert bad.title == "미세먼지 나쁨" and bad.slides[0].rows[-1].label == "이렇게 해요" + wet = _air(10, 20, rain=True) + assert "창문은 닫아" in wet.slides[0].line and wet.icon == "umbrella" + assert "창문은 닫아" not in _air(40, 60, rain=True).slides[0].line very = _air(20, 160) - assert very.title == "미세먼지 매우나쁨" and "측정소" in very.caption and very.slides[0].rows[1].value == "160㎍/㎥ · 매우나쁨" + assert very.title == "미세먼지 매우나쁨" and "측정소" in very.caption and very.slides[0].rows[1].value == "매우나쁨" def test_air_post_off_without_fresh_data():