From aef8b4a022cc15e49f9edd1f197fb9b52a15f4f2 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Wed, 21 Oct 2026 17:24:02 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=B0=BD?= =?UTF-8?q?=EC=97=90=20=EB=82=A8=EC=9D=80=20'=EB=98=90=EB=8A=94=20?= =?UTF-8?q?=EC=95=84=EC=9D=B4=EB=94=94=EB=A1=9C'=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=EC=84=A0=EA=B3=BC=20'=EC=95=84=EC=9D=B4=EB=94=94=EB=A1=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=ED=95=B4=20=EC=A3=BC=EC=84=B8?= =?UTF-8?q?=EC=9A=94'=20=EC=95=88=EB=82=B4=20=EB=B9=BC=EA=B8=B0,=20?= =?UTF-8?q?=EB=B9=88=20=EC=98=A4=EB=A5=98=20=EC=B9=B8=20=EC=97=AC=EB=B0=B1?= =?UTF-8?q?=20=EC=A4=84=EC=9D=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/router/v1/seo/seo.py | 16 ++++++++++++++++ backend/services/seo_service.py | 33 ++++++++++++++++++++++++--------- backend/tests/test_seo.py | 24 +++++++++++++++++++++++- frontend/nginx.conf | 4 ++-- frontend/src/App.tsx | 1 + frontend/src/b/BLayout.tsx | 2 +- frontend/src/b/Sheets.tsx | 2 +- frontend/src/b/googleLogin.tsx | 3 +-- frontend/src/b/region.tsx | 10 ++++++---- frontend/vite.config.ts | 12 +++++++++++- 10 files changed, 86 insertions(+), 21 deletions(-) diff --git a/backend/router/v1/seo/seo.py b/backend/router/v1/seo/seo.py index 6062a60..1a0ccc8 100644 --- a/backend/router/v1/seo/seo.py +++ b/backend/router/v1/seo/seo.py @@ -23,3 +23,19 @@ async def get_today_gu_page(sido: str = Path(..., pattern=_SLUG), place: str = P if err is not ErrorType.SUCCESS: return HTMLResponse("not found", status_code=404) return HTMLResponse(html, headers={"Cache-Control": "no-cache"}) + + +@router.get("/tomorrow/{sido}/{place}", response_class=HTMLResponse, summary="지역 내일 날씨 페이지: 정적 HTML 에 내일 예보를 채운다 (nginx 가 /tomorrow/... 를 넘김)") +async def get_tomorrow_page(sido: str = Path(..., pattern=_SLUG), place: str = Path(..., pattern=_SLUG), service: SeoService = Depends()) -> HTMLResponse: + err, html = await service.page(f"tomorrow/{sido}/{place}") + if err is not ErrorType.SUCCESS: + return HTMLResponse("not found", status_code=404) + return HTMLResponse(html, headers={"Cache-Control": "no-cache"}) + + +@router.get("/tomorrow/{sido}/{place}/{gu}", response_class=HTMLResponse, summary="구로 나뉜 시의 구 내일 날씨 페이지") +async def get_tomorrow_gu_page(sido: str = Path(..., pattern=_SLUG), place: str = Path(..., pattern=_SLUG), gu: str = Path(..., pattern=_SLUG), service: SeoService = Depends()) -> HTMLResponse: + err, html = await service.page(f"tomorrow/{sido}/{place}/{gu}") + if err is not ErrorType.SUCCESS: + return HTMLResponse("not found", status_code=404) + return HTMLResponse(html, headers={"Cache-Control": "no-cache"}) diff --git a/backend/services/seo_service.py b/backend/services/seo_service.py index b2c76fb..6ea2764 100644 --- a/backend/services/seo_service.py +++ b/backend/services/seo_service.py @@ -21,7 +21,7 @@ from services.feed_service import FeedService _CODE = re.compile(r'(.+?) 오늘 날씨") +_NAME = re.compile(r"

(.+?) (?:오늘|내일) 날씨") _H1 = re.compile(r"(

[^<]*

)") @@ -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'
  1. {escape(t.name)} {t.score}점
  2. ' for t in top)}
" if top else "" - 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)}

{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() { }> } /> } /> + } /> } /> } /> } /> diff --git a/frontend/src/b/BLayout.tsx b/frontend/src/b/BLayout.tsx index 4bf814b..d65adcb 100644 --- a/frontend/src/b/BLayout.tsx +++ b/frontend/src/b/BLayout.tsx @@ -232,7 +232,7 @@ function Shell() { {TABS.map((t) => t.key === 'today' ? ( // 메인 탭: 막대 위로 솟은 큰 주황 동그라미 - cx('b-tab-main relative -mt-6 flex flex-col items-center gap-1 text-[12px] font-extrabold', isActive || pathname.startsWith('/today/') ? 'text-(--orange)' : 'text-(--ink3)')}> + cx('b-tab-main relative -mt-6 flex flex-col items-center gap-1 text-[12px] font-extrabold', isActive || pathname.startsWith('/today/') || pathname.startsWith('/tomorrow/') ? 'text-(--orange)' : 'text-(--ink3)')}> diff --git a/frontend/src/b/Sheets.tsx b/frontend/src/b/Sheets.tsx index 7303ef3..29cb333 100644 --- a/frontend/src/b/Sheets.tsx +++ b/frontend/src/b/Sheets.tsx @@ -831,7 +831,7 @@ function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: () }} onFail={fail} /> -

    +

    {error}