[^<]*
)") @@ -61,15 +61,27 @@ def today_line(feed: Res_Feed, rows: list[WeatherHourly], sunset_at: Optional[da return " ".join(parts) -def fill(template: str, feed: Res_Feed, rows: list[WeatherHourly], name: str, sunset_at: Optional[datetime]) -> str: - """정적 지역 페이지에 오늘 값을 채운다: 설명 메타와 본문 첫 단락, 오늘 각 순위.""" - line = today_line(feed, rows, sunset_at) +def tomorrow_line(rows: list[WeatherHourly], sunset_at: Optional[datetime]) -> str: + """내일 페이지 한 줄: 내일 하루 예보와 해 지는 시각.""" + parts = [day_summary(rows)] if rows else [] + if parts and sunset_at: + parts.append(f"해 지는 시각 {_clock(sunset_at)}.") + return " ".join(parts) + + +def _put(template: str, line: str, extra: str = "") -> str: + """설명 메타와 본문 h1 바로 아래에 한 줄을 넣는다.""" if not line: return template + html = _DESC.sub(lambda m: f'{m.group(1)}{escape(line, quote=True)}"', template) + return _H1.sub(lambda m: f"{m.group(1)}{escape(line)}
{extra}", html, count=1) + + +def fill(template: str, feed: Res_Feed, rows: list[WeatherHourly], name: str, sunset_at: Optional[datetime]) -> str: + """정적 지역 페이지에 오늘 값을 채운다: 설명 메타와 본문 첫 단락, 오늘 각 순위.""" top = feed.bands.top5 if feed.bands else [] ranks = f"오늘 {escape(name)} 각 순위
- {''.join(f'
- {escape(t.name)} {t.score}점 ' for t in top)}
{escape(line)}
{ranks}", html, count=1) + return _put(template, today_line(feed, rows, sunset_at), ranks) class SeoService: @@ -98,9 +110,12 @@ class SeoService: LOG.error(f"[seo] feed {code}: {err}") return ErrorType.SUCCESS, template _, region = await DB_SESSION_MNG.execute_lambda(lambda s: self.regions.get(s, code)) - today = now_kst().date() - sunset_at = sun_times(today, float(region.lat), float(region.lon)).sunset_at if region else None - start = kst_midnight(today) + ahead = path.startswith("tomorrow/") + day = now_kst().date() + timedelta(days=1 if ahead else 0) + sunset_at = sun_times(day, float(region.lat), float(region.lon)).sunset_at if region else None + start = kst_midnight(day) _, rows = await DB_SESSION_MNG.execute_lambda(lambda s: self.weather.hourly_between(s, code, start, start + timedelta(days=1))) + if ahead: + return ErrorType.SUCCESS, _put(template, tomorrow_line(rows or [], sunset_at)) name = _NAME.search(template) return ErrorType.SUCCESS, fill(template, feed, rows or [], name.group(1) if name else (feed.region_name or ""), sunset_at) diff --git a/backend/tests/test_seo.py b/backend/tests/test_seo.py index b64ef02..edc88c3 100644 --- a/backend/tests/test_seo.py +++ b/backend/tests/test_seo.py @@ -7,7 +7,7 @@ from common.utils.kma_time import KST from common.database.model.models import WeatherHourly from router.router import app from router.v1.feed.protocol import Bands, Hero, HeroStat, Res_Feed, TopIndex -from services.seo_service import SeoService, day_summary, fill, today_line +from services.seo_service import SeoService, day_summary, fill, today_line, tomorrow_line REGION = "1114000000" TEMPLATE = ( @@ -76,3 +76,25 @@ async def test_gu_page_of_city_has_its_own_address(offline, monkeypatch): async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: page = await client.get("/v1/seo/today/gyeonggi/seongnam/bundang") assert page.status_code == 200 and "지금 20°" in page.text + + +def test_tomorrow_line_has_day_and_sunset(): + line = tomorrow_line([_hour(12, 19.5, prob=10)], datetime(2026, 10, 15, 17, 51, tzinfo=KST)) + assert line == "최저 20°·최고 20°, 강수확률 10%, 맑음. 해 지는 시각 오후 5시 51분." + assert tomorrow_line([], datetime(2026, 10, 15, 17, 51, tzinfo=KST)) == "" + + +@pytest.mark.anyio +async def test_tomorrow_page_fills_tomorrow_forecast(offline, monkeypatch): + tmpl = TEMPLATE.replace("오늘 날씨", "내일 날씨") + + async def template(self, path): + return tmpl if path == "tomorrow/gyeonggi/seongnam/bundang" else None + + monkeypatch.setattr(SeoService, "template", template) + async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: + page = await client.get("/v1/seo/tomorrow/gyeonggi/seongnam/bundang") + missing = await client.get("/v1/seo/tomorrow/seoul/nowhere") + assert page.status_code == 200 and "서울 중구 내일 날씨, 뭐 할까?
최저 " in page.text + assert "지금 " not in page.text and "
- " not in page.text
+ assert missing.status_code == 404
diff --git a/frontend/nginx.conf b/frontend/nginx.conf
index f92b0c5..8cc3b1d 100644
--- a/frontend/nginx.conf
+++ b/frontend/nginx.conf
@@ -37,8 +37,8 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
}
- # 지역 검색 페이지: 백엔드가 정적 HTML(today/…/….html)에 오늘 날씨를 채워 준다. 백엔드가 안 되면 정적 HTML 그대로
- location ~ ^/today/[a-z]+/[a-z]+(/[a-z]+)?$ {
+ # 지역 검색 페이지: 백엔드가 정적 HTML(today·tomorrow/…/….html)에 오늘·내일 날씨를 채워 준다. 백엔드가 안 되면 정적 HTML 그대로
+ location ~ ^/(today|tomorrow)/[a-z]+/[a-z]+(/[a-z]+)?$ {
resolver 127.0.0.11 valid=10s ipv6=off;
set $api http://backend:9800;
proxy_pass $api/v1/seo$uri;
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 88502e3..7426677 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -13,6 +13,7 @@ export default function App() {
+
{error}