feat: 날씨각 백엔드 API (날씨·노을·지수·주말·계절·피드·로그인·반응)

- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가
- 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시)
- 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리
- 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리
- pytest 66개 (테스트 전용 DB·Redis 사용)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-10-02 11:32:22 +09:00
1 parent 9cdc0d8fea
commit e134295ce5
135 files changed
+9123

No files matched your search

View File
Whitespace-only changes.
+19
View File
@@ -0,0 +1,19 @@
import math
_EARTH_RADIUS_KM = 6371.0088
def haversine_km(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
p1, p2 = math.radians(lat1), math.radians(lat2)
dp, dl = p2 - p1, math.radians(lon2 - lon1)
a = math.sin(dp / 2) ** 2 + math.cos(p1) * math.cos(p2) * math.sin(dl / 2) ** 2
return 2 * _EARTH_RADIUS_KM * math.asin(math.sqrt(a))
def destination(lat: float, lon: float, bearing_deg: float, km: float) -> tuple[float, float]:
"""출발점에서 방위각 방향으로 km 떨어진 지점."""
d = km / _EARTH_RADIUS_KM
p1, l1, b = math.radians(lat), math.radians(lon), math.radians(bearing_deg)
p2 = math.asin(math.sin(p1) * math.cos(d) + math.cos(p1) * math.sin(d) * math.cos(b))
l2 = l1 + math.atan2(math.sin(b) * math.sin(d) * math.cos(p1), math.cos(d) - math.sin(p1) * math.sin(p2))
return math.degrees(p2), (math.degrees(l2) + 540) % 360 - 180
+39
View File
@@ -0,0 +1,39 @@
from datetime import date, datetime, time, timedelta, timezone
KST = timezone(timedelta(hours=9))
VILAGE_BASE_HOURS = (2, 5, 8, 11, 14, 17, 20, 23)
VILAGE_DELAY = timedelta(minutes=10)
ULTRA_DELAY = timedelta(minutes=15)
def now_kst() -> datetime:
return datetime.now(KST)
def kst_midnight(d: date) -> datetime:
return datetime.combine(d, time(0), tzinfo=KST)
def latest_vilage_base(now: datetime) -> datetime:
"""지금 받을 수 있는 가장 최근 단기예보 발표 시각 (발표 10분 뒤부터 제공)."""
now = now.astimezone(KST)
for day_offset in (0, 1):
d = (now - timedelta(days=day_offset)).date()
for h in reversed(VILAGE_BASE_HOURS):
base = datetime.combine(d, time(h), tzinfo=KST)
if base + VILAGE_DELAY <= now:
return base
raise AssertionError("unreachable")
def next_vilage_available(now: datetime) -> datetime:
"""다음 단기예보가 제공되는 시각."""
return latest_vilage_base(now) + timedelta(hours=3) + VILAGE_DELAY
def latest_ultra_base(now: datetime) -> datetime:
"""지금 받을 수 있는 가장 최근 초단기예보 발표 시각 (매시 30분 발표, 45분부터 제공)."""
now = now.astimezone(KST)
base = now.replace(minute=30, second=0, microsecond=0)
return base if base + ULTRA_DELAY <= now else base - timedelta(hours=1)
+19
View File
@@ -0,0 +1,19 @@
def hour_label(h: int) -> str:
if h == 0:
return "자정"
if h < 12:
return f"오전 {h}시"
if h == 12:
return "낮 12시"
return f"오후 {h - 12}시"
def ieyo(word: str) -> str:
"""받침이 있으면 '이에요', 없으면 '예요'."""
last = word[-1] if word else ""
has_final = "가" <= last <= "힣" and (ord(last) - 0xAC00) % 28 != 0
return f"{word}이에요" if has_final else f"{word}예요"
def month_day(d) -> str:
return f"{d.month}월 {d.day}일"