fix: 서울문화포털 축제 이름 앞 [주최 기관] 떼기

This commit is contained in:
minaChoi committed 2026-10-08 13:08:09 +09:00
1 parent b4fcb313c7
commit f1a46ea4a2
2 files changed
+5 -1

No files matched your search

+4 -1
View File
@@ -1,5 +1,6 @@
import asyncio import asyncio
import html import html
import re
from datetime import date, timedelta from datetime import date, timedelta
from typing import Optional from typing import Optional
@@ -16,6 +17,8 @@ SOURCE_PREFIX = "seoul:"
SEOUL = "11" SEOUL = "11"
REQUEST_GAP_SEC = 0.3 REQUEST_GAP_SEC = 0.3
_MAX_PAGES = 30 _MAX_PAGES = 30
# 이름 앞 주최 기관 "[서울시청] ", "[마포문화재단] " 은 카드 제목에서 뗀다
_HOST_PREFIX = re.compile(r"^(\s*\[[^\]]*\]\s*)+")
async def fetch_seoul_festivals(client: httpx.AsyncClient, since: date, days: int) -> list[dict]: async def fetch_seoul_festivals(client: httpx.AsyncClient, since: date, days: int) -> list[dict]:
@@ -51,7 +54,7 @@ def parse_seoul_festivals(items: list[dict]) -> list[dict]:
rows = [] rows = []
for it in items: for it in items:
start, end = _date(it.get("strtdate")), _date(it.get("endDate")) start, end = _date(it.get("strtdate")), _date(it.get("endDate"))
name = html.unescape(it.get("title") or "").strip() name = _HOST_PREFIX.sub("", html.unescape(it.get("title") or "")).strip()
if start is None or end is None or not name or it.get("cultcode") is None: if start is None or end is None or not name or it.get("cultcode") is None:
continue continue
rows.append({ rows.append({
+1
View File
@@ -17,6 +17,7 @@ def test_parse_reads_lat_from_x_and_builds_image_and_link():
[row] = parse_seoul_festivals([ITEM, {**ITEM, "cultcode": None}, {**ITEM, "cultcode": 2, "strtdate": ""}]) [row] = parse_seoul_festivals([ITEM, {**ITEM, "cultcode": None}, {**ITEM, "cultcode": 2, "strtdate": ""}])
assert row["source_id"] == "seoul:159216" and row["sido_code"] == "11" assert row["source_id"] == "seoul:159216" and row["sido_code"] == "11"
assert (row["lat"], row["lon"]) == (37.51182, 127.05916) assert (row["lat"], row["lon"]) == (37.51182, 127.05916)
assert row["name"] == "2026 중랑용마폭포축제"
assert row["place_name"] == "용마폭포공원" and row["start_date"] == date(2026, 10, 10) assert row["place_name"] == "용마폭포공원" and row["start_date"] == date(2026, 10, 10)
assert row["image_url"].endswith("atchFileId=abc&thumb=Y") and "cultcode=159216" in row["source_url"] assert row["image_url"].endswith("atchFileId=abc&thumb=Y") and "cultcode=159216" in row["source_url"]