- 각 포스트: 각마다 같던 근거 표·요약 줄을 빼고 오늘·내일·주말 점수 칸(각 상세와 같은 값), 작은 화면에서 점수·그림 줄임 - 밤 화면에서도 포스트 본문은 낮 색 그대로, 어두운 각 배경(캠핑·별보기·산책)과 행사 밤하늘 배경 뺌 - 히어로 좋아요·댓글·보내기 간격·높이 맞춤 - 동네 사람들 묶음을 글 1개부터 보이게 (3개 미만이면 자기 글도 안 보이던 문제) - QA 체크리스트에 쇼츠·각 포스트 결과, TODO 에 쇼츠 공유 링크 빈 화면
255 lines
9.0 KiB
Python
255 lines
9.0 KiB
Python
from datetime import date, datetime
|
||
from typing import Annotated, Literal, Optional, Union
|
||
|
||
from pydantic import Field
|
||
|
||
from common.enums import PostType, SkySituation, SlotTone
|
||
from common.models.gmodel import Res_WebPacketProtocol, WebPacketProtocol
|
||
from router.v1.index.protocol import TrendPoint
|
||
|
||
|
||
class Row(WebPacketProtocol):
|
||
label: str
|
||
value: str
|
||
place: Optional[str] = Field(default=None, description="위치가 정해진 장소면 지도에서 찾을 이름 (앱이 네이버 지도 링크를 건다)")
|
||
level: Optional[int] = Field(default=None, description="자외선 단계 1 낮음 ~ 5 위험. 있으면 앱이 값을 단계 색 칩으로 그린다")
|
||
|
||
|
||
class HourCell(WebPacketProtocol):
|
||
label: str
|
||
icon: str
|
||
temp_c: Optional[float] = None
|
||
tone: SlotTone
|
||
|
||
|
||
class HoursSlide(WebPacketProtocol):
|
||
kind: Literal["hours"]
|
||
eyebrow: str
|
||
line: str
|
||
hours: list[HourCell]
|
||
|
||
|
||
class RowsSlide(WebPacketProtocol):
|
||
"""우산·미세먼지·계절 소식·행사·상식처럼 '한 줄 + 표' 모양."""
|
||
|
||
kind: Literal["rows"]
|
||
eyebrow: str
|
||
line: str
|
||
icon: str
|
||
rows: list[Row] = []
|
||
image: Optional[str] = None # 있으면 아이콘 대신 카드 전체에 사진
|
||
image_credit: Optional[str] = None # 사진 출처 표기 ("ⓒ한국관광공사")
|
||
|
||
|
||
class GakSlide(WebPacketProtocol):
|
||
kind: Literal["gak"]
|
||
index_id: int
|
||
code: str
|
||
name: str
|
||
rank: int
|
||
score: int
|
||
line: str
|
||
summary: str
|
||
say: Optional[str] = Field(default=None, description="점수 구간 설명 문장 (seed sentences)")
|
||
trend: list[TrendPoint] = Field(default=[], description="오늘 · 내일 · 이번 주말 점수 (각 상세 날짜 칸과 같은 값)")
|
||
|
||
|
||
class Cut(WebPacketProtocol):
|
||
at: datetime
|
||
kind: str
|
||
label: str
|
||
|
||
|
||
class SunsetSlide(WebPacketProtocol):
|
||
kind: Literal["sunset"]
|
||
eyebrow: str
|
||
line: str
|
||
score: int
|
||
grade_label: str
|
||
cuts: list[Cut]
|
||
situation: Optional[SkySituation] = Field(default=None, description="하늘 상황. 앱이 카드 하늘 색을 고른다")
|
||
headline: Optional[str] = Field(default=None, description="결론 (나가 볼 만해요 · 애매해요 · 쉬어요). 카드 맨 위에 크게")
|
||
peak_at: Optional[datetime] = Field(default=None, description="가장 붉을 때")
|
||
|
||
|
||
class WeekGak(WebPacketProtocol):
|
||
index_id: int
|
||
name: str
|
||
icon: str
|
||
score: int
|
||
|
||
|
||
class WeekDay(WebPacketProtocol):
|
||
day: date
|
||
weekday: str
|
||
icon: str
|
||
text: str
|
||
temp_min_c: Optional[float] = None
|
||
temp_max_c: Optional[float] = None
|
||
rain_prob: Optional[int] = None
|
||
gaks: list[WeekGak] = Field(default_factory=list, description="그날 대표 각 (중요도 배율을 반영한 최종 표시 점수 내림차순 3개, 동점이면 중요도 순). 각 점수가 아직 없는 날은 비어 있음")
|
||
|
||
|
||
class WeekSlide(WebPacketProtocol):
|
||
"""주말 예보: 토·일 비교 + 옷차림·우산 팁."""
|
||
|
||
kind: Literal["week"]
|
||
eyebrow: str
|
||
line: str
|
||
days: list[WeekDay]
|
||
tip: Optional[str] = None
|
||
|
||
|
||
class PlanStep(WebPacketProtocol):
|
||
time: str
|
||
icon: str
|
||
title: str
|
||
sub: str
|
||
image: Optional[str] = None # 행사 사진
|
||
image_credit: Optional[str] = None
|
||
|
||
|
||
class PlanSlide(WebPacketProtocol):
|
||
"""주말 플랜: 그날 시간대별 동선."""
|
||
|
||
kind: Literal["plan"]
|
||
eyebrow: str
|
||
line: str
|
||
steps: list[PlanStep]
|
||
|
||
|
||
class ImageSlide(WebPacketProtocol):
|
||
"""카드뉴스 한 장 (1080×1350 JPEG). url 은 같은 서버의 /v1/card/... 경로."""
|
||
|
||
kind: Literal["image"]
|
||
url: str
|
||
alt: str = ""
|
||
|
||
|
||
Slide = Annotated[Union[HoursSlide, RowsSlide, GakSlide, SunsetSlide, WeekSlide, PlanSlide, ImageSlide], Field(discriminator="kind")]
|
||
|
||
|
||
class PostData(WebPacketProtocol):
|
||
post_id: int
|
||
post_type: PostType
|
||
title: str
|
||
icon: str
|
||
caption: str
|
||
slides: list[Slide]
|
||
share_messages: list[str] = []
|
||
like_count: int
|
||
comment_count: int
|
||
published_at: datetime
|
||
size: Literal["full", "line"] = "full" # line: 한 줄 카드 (흐린 날 노을)
|
||
liked: Optional[bool] = None
|
||
saved: Optional[bool] = None
|
||
|
||
|
||
class PostReaction(WebPacketProtocol):
|
||
"""포스트 틀이 아닌 카드(히어로·오늘의 각·단풍 지도·띠)에 붙는 좋아요·댓글."""
|
||
post_id: int
|
||
like_count: int
|
||
comment_count: int
|
||
liked: Optional[bool] = None
|
||
|
||
|
||
class TopIndex(WebPacketProtocol):
|
||
index_id: int
|
||
code: str
|
||
name: str
|
||
icon: str
|
||
score: int
|
||
rank: int
|
||
summary: Optional[str] = None
|
||
active: bool = Field(default=True, description="지금 구간이 이 각의 시간대와 겹침. false 면 순위 밖, score 는 하루 점수")
|
||
slots: dict[str, int] = Field(default_factory=dict, description="오늘 구간별 점수 {morning·day·evening·night: 점수}. 각 시간대와 안 겹치는 구간은 없음")
|
||
slot_ranks: dict[str, int] = Field(default_factory=dict, description="오늘 구간별 순위 (중요도 배율을 반영한 최종 표시 점수 내림차순, 동점이면 중요도 순)")
|
||
|
||
|
||
class HeroStat(WebPacketProtocol):
|
||
icon: str
|
||
label: str
|
||
value: str
|
||
tone: Literal["normal", "warn", "rain"] = Field(description="normal=기본, warn=조심(노랑), rain=비(파랑)")
|
||
detail: Optional[str] = Field(default=None, description="단계 이름 밑의 실제 값 (예: 68%, 72, 2, 초미세먼지 15㎍/㎥). 상태 줄에만")
|
||
|
||
|
||
class WeatherWhy(WebPacketProtocol):
|
||
label: str
|
||
weight: int = Field(description="비중 % (합 100)")
|
||
score: int = Field(description="이 조건 점수 0~100")
|
||
note: str = Field(description="지금 값 (예: 체감 19°, 편한 범위 18~24° 안)")
|
||
|
||
|
||
class HeroTomorrow(WebPacketProtocol):
|
||
"""히어로 '내일' 스위치. 3시간 칸 날씨는 /v1/weather/today?day=tomorrow 로 따로 받는다."""
|
||
day: date
|
||
weather_slots: dict[str, int] = Field(default_factory=dict, description="내일 구간별 날씨 점수 {morning·day·evening·night: 점수}")
|
||
weather_why: dict[str, list[WeatherWhy]] = Field(default_factory=dict, description="내일 구간별 날씨 점수 근거")
|
||
top1: Optional[TopIndex] = Field(default=None, description="내일 하루 점수로 1위인 각. score·summary 는 내일 값")
|
||
|
||
|
||
class Hero(WebPacketProtocol):
|
||
now_at: datetime
|
||
sky_mode: Literal["morning", "day", "sunset", "night"]
|
||
temp_c: Optional[float] = None
|
||
feels_c: Optional[float] = None
|
||
humidity: Optional[int] = Field(default=None, description="지금 습도 %. 히어로에 늘 보인다")
|
||
discomfort: Optional[int] = Field(default=None, description="지금 불쾌지수. 히어로에 늘 보인다")
|
||
discomfort_label: Optional[str] = None
|
||
rain_2h_text: Optional[str] = None
|
||
will_rain_2h: Optional[bool] = None
|
||
weather_score: Optional[int] = None
|
||
weather_slots: dict[str, int] = Field(default_factory=dict, description="오늘 구간별 날씨 점수 {morning·day·evening·night: 점수}")
|
||
weather_why: dict[str, list[WeatherWhy]] = Field(default_factory=dict, description="구간별 날씨 점수 근거(조건·비중·조건 점수·지금 값). 키는 weather_slots 와 같다")
|
||
top1: Optional[TopIndex] = None
|
||
bubble: Optional[str] = None
|
||
moon_name: Optional[str] = Field(default=None, description="오늘 밤 달 모양: 삭·초승달·상현달·차오르는 달·보름달·기우는 달·하현달·그믐달")
|
||
moon_pct: Optional[int] = Field(default=None, description="달에서 빛나는 면의 비율 0~100 (모양 그림용, 밝기 아님)")
|
||
stats: list[HeroStat] = Field(default_factory=list, description="히어로 상황 칸 1개. 지금 챙길 것(비·미세먼지·자외선·일교차·체감) 먼저")
|
||
status: list[HeroStat] = Field(default_factory=list, description="히어로 상태 한 줄: 습도·불쾌지수·자외선(밤 구간 빼고)·미세먼지 단계 이름. tone=warn 이면 조심(앱이 주황 글자로)")
|
||
tomorrow: Optional[HeroTomorrow] = None
|
||
|
||
|
||
class BandEvent(WebPacketProtocol):
|
||
event_id: int
|
||
name: str
|
||
status_label: str
|
||
icon: str
|
||
image: Optional[str] = None
|
||
image_credit: Optional[str] = None
|
||
|
||
|
||
class BandArticle(WebPacketProtocol):
|
||
article_id: int
|
||
title: str
|
||
meta: str
|
||
icon: str
|
||
image: Optional[str] = None
|
||
image_credit: Optional[str] = None
|
||
|
||
|
||
class Bands(WebPacketProtocol):
|
||
events: list[BandEvent] = []
|
||
top5: list[TopIndex] = []
|
||
season: list[BandArticle] = []
|
||
|
||
|
||
class Res_Feed(Res_WebPacketProtocol):
|
||
region_code: Optional[str] = None
|
||
region_name: Optional[str] = None
|
||
slot: Optional[Literal["morning", "day", "evening", "night"]] = None # 피드 순서를 정한 시간대
|
||
hero: Optional[Hero] = None
|
||
stories: list[TopIndex] = []
|
||
posts: list[PostData] = []
|
||
hero_post: Optional[PostReaction] = None
|
||
gak_post: Optional[PostReaction] = None
|
||
foliage_post: Optional[PostReaction] = None
|
||
events_post: Optional[PostReaction] = None
|
||
season_post: Optional[PostReaction] = None
|
||
bands: Optional[Bands] = None
|
||
|
||
|
||
class Res_Post(Res_WebPacketProtocol):
|
||
post: Optional[PostData] = None
|