Merge remote-tracking branch 'origin/main' into feat/my-gak
This commit is contained in:
commit
12f4eca8a8
22 files changed
+3247
-16
No files matched your search
@@ -0,0 +1,60 @@
|
||||
"""/faq 지역 질문에 넣을 지역별 장소를 시드로 다시 만든다. 시도마다 한 파일: frontend/seo/region_faq/seoul.json
|
||||
|
||||
region.json 이나 place*.csv, sunset_spot.csv 가 바뀌면 실행: python backend/scripts/gen_region_faq.py
|
||||
앱 번들에 들어가는 region.json 을 키우지 않으려고 따로 둔다. vite 빌드가 /faq 를 만들 때만 읽는다.
|
||||
"""
|
||||
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
SEED = os.path.join(ROOT, "backend", "seed")
|
||||
PAGES = os.path.join(ROOT, "frontend", "seo", "region.json")
|
||||
OUT = os.path.join(ROOT, "frontend", "seo", "region_faq")
|
||||
|
||||
OUTDOOR, INDOOR, SUNSET = 3, 2, 2
|
||||
|
||||
|
||||
def rows(name: str) -> list[dict]:
|
||||
return list(csv.DictReader(open(os.path.join(SEED, name), encoding="utf-8")))
|
||||
|
||||
|
||||
# 손으로 고른 장소를 관광공사 장소보다 먼저
|
||||
places = rows("place.csv") + rows("place_tourapi.csv")
|
||||
sunsets = rows("sunset_spot.csv")
|
||||
|
||||
|
||||
def pick(found: list[dict], n: int) -> list[str]:
|
||||
"""아이콘(산책·피크닉·사진…)이 겹치지 않게 먼저 고르고, 모자라면 순서대로 채운다."""
|
||||
out, icons = [], set()
|
||||
for p in found:
|
||||
if p["icon"] not in icons and p["name"] not in out:
|
||||
out.append(p["name"])
|
||||
icons.add(p["icon"])
|
||||
for p in found:
|
||||
if p["name"] not in out:
|
||||
out.append(p["name"])
|
||||
return out[:n]
|
||||
|
||||
|
||||
result = {}
|
||||
for page in json.load(open(PAGES, encoding="utf-8")):
|
||||
names = {r["name"] for r in page["regions"]}
|
||||
mine = [p for p in places if p["region_name"] in names]
|
||||
result[page["path"]] = dict(
|
||||
outdoor=pick([p for p in mine if p["is_outdoor"] == "1"], OUTDOOR),
|
||||
indoor=pick([p for p in mine if p["is_outdoor"] == "0"], INDOOR),
|
||||
sunset=list(dict.fromkeys(s["name"] for s in sunsets if s["region_name"] in names))[:SUNSET],
|
||||
)
|
||||
# 시도마다 한 파일 (seoul.json). 지난번에 만든 시도 파일은 지우고 다시 쓴다
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
for f in os.listdir(OUT):
|
||||
if f.endswith(".json"):
|
||||
os.remove(os.path.join(OUT, f))
|
||||
by_sido = {}
|
||||
for path, spots in result.items():
|
||||
by_sido.setdefault(path.split("/")[0], {})[path] = spots
|
||||
for sido, part in by_sido.items():
|
||||
json.dump(part, open(os.path.join(OUT, f"{sido}.json"), "w", encoding="utf-8"), ensure_ascii=False, indent=1)
|
||||
print(len(result), "pages", sum(any(v.values()) for v in result.values()), "with places", len(by_sido), "files")
|
||||
Reference in new issue
Block a user