- 행사 수집을 화면 요청에서 빼고 worker 가 월 04:00(켤 때 7일 기록 없으면 한 번) 전국 17개 시도를 받는다 - 문화정보원 음악/콘서트(B000) 추가, 쪽·시도 사이 1초 간격으로 초당 요청 제한 회피 - 팝가(popga.co.kr) 팝업스토어 수집: 사이트맵 + 상세 JSON-LD, 바뀐 페이지만 다시 읽음 - 수집이 끝나면 Teams Workflows webhook 으로 종류별 건수 알림 (TEAMS_WEBHOOK_URL) - event.kind(1=축제 2=전시 3=콘서트 4=팝업) 칸과 종류별 아이콘 추가 - 피드 행사 카드·띠를 축제→팝업→전시→콘서트 차례로 섞음 - 포스트 종류별 내용·피드 기획 문서 갱신 같은 작업 폴더의 다른 작업(외부 API 가드, 노을·달 계산, 각 API, 문서 파일 이름 정리 등)도 함께 담김.
55 lines
2.7 KiB
Python
55 lines
2.7 KiB
Python
from datetime import date
|
|
|
|
from sqlalchemy import delete, func, select
|
|
from sqlalchemy.dialects.postgresql import insert
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from common.database.model.models import Event, Holiday, Place, WeatherDaily
|
|
|
|
|
|
class WeekCRUD:
|
|
async def daily(self, s: AsyncSession, region_code: str, since: date, until: date) -> list[WeatherDaily]:
|
|
stmt = select(WeatherDaily).where(
|
|
WeatherDaily.region_code == region_code, WeatherDaily.forecast_date >= since, WeatherDaily.forecast_date <= until
|
|
)
|
|
return list((await s.scalars(stmt.order_by(WeatherDaily.forecast_date))).all())
|
|
|
|
async def holidays(self, s: AsyncSession, since: date, until: date) -> dict[date, str]:
|
|
stmt = select(Holiday).where(Holiday.holiday_date >= since, Holiday.holiday_date <= until)
|
|
return {h.holiday_date: h.name for h in (await s.scalars(stmt)).all()}
|
|
|
|
async def holiday_count(self, s: AsyncSession, year: int) -> int:
|
|
stmt = select(func.count()).select_from(Holiday).where(func.extract("year", Holiday.holiday_date) == year)
|
|
return await s.scalar(stmt)
|
|
|
|
async def upsert_holidays(self, s: AsyncSession, rows: list[dict]) -> None:
|
|
if rows:
|
|
await s.execute(insert(Holiday).values(rows).on_conflict_do_nothing(index_elements=["holiday_date", "name"]))
|
|
|
|
async def places(self, s: AsyncSession, sido_code: str) -> list[Place]:
|
|
stmt = select(Place).where(Place.region_code.startswith(sido_code)).order_by(Place.sort_order)
|
|
return list((await s.scalars(stmt)).all())
|
|
|
|
async def replace_places(self, s: AsyncSession, rows: list[dict]) -> None:
|
|
await s.execute(delete(Place))
|
|
if rows:
|
|
await s.execute(insert(Place).values(rows))
|
|
|
|
async def events(self, s: AsyncSession, sido_codes: list[str], since: date, until: date) -> list[Event]:
|
|
stmt = select(Event).where(Event.sido_code.in_(sido_codes), Event.end_date >= since, Event.start_date <= until)
|
|
return list((await s.scalars(stmt.order_by(Event.start_date))).all())
|
|
|
|
async def upsert_events(self, s: AsyncSession, rows: list[dict]) -> None:
|
|
if not rows:
|
|
return
|
|
stmt = insert(Event).values(rows)
|
|
await s.execute(stmt.on_conflict_do_update(
|
|
index_elements=["source_id"],
|
|
set_={k: stmt.excluded[k] for k in ("name", "place_name", "start_date", "end_date", "is_confirmed", "image_url", "lat", "lon", "kind", "icon")},
|
|
))
|
|
|
|
async def replace_manual_events(self, s: AsyncSession, rows: list[dict]) -> None:
|
|
await s.execute(delete(Event).where(Event.source_id.is_(None)))
|
|
if rows:
|
|
await s.execute(insert(Event).values(rows))
|