import sys
import os
import asyncio
from dotenv import load_dotenv
# Ensure import works
current_dir = os.path.dirname(os.path.abspath(__file__))
if current_dir not in sys.path:
sys.path.insert(0, current_dir)
try:
from server import fetch_ultra_srt_ncst, get_ultra_short_term_forecast, convert_latlon_to_grid
except ImportError:
# Fallback if running from root
sys.path.append(os.path.join(current_dir, "src"))
from src.server import fetch_ultra_srt_ncst, get_ultra_short_term_forecast, convert_latlon_to_grid
load_dotenv()
async def main():
# Gangnam-gu Office Coordinates
lat = 37.5172
lon = 127.0473
nx, ny = convert_latlon_to_grid(lat, lon)
print(f"π Gangnam-gu ({lat}, {lon}) -> Grid ({nx}, {ny})")
print("\n1οΈβ£ Fetching Current Weather...")
try:
import json
result_str = await fetch_ultra_srt_ncst(nx, ny)
data = json.loads(result_str)
try:
items = data['response']['body']['items']['item']
weather = {}
for item in items:
weather[item['category']] = item['obsrValue']
t1h = float(weather.get('T1H', -999))
pty = int(weather.get('PTY', 0))
reh = float(weather.get('REH', 0))
wsd = float(weather.get('WSD', 0))
pty_map = {0: "μμ", 1: "λΉ", 2: "λΉ/λ", 3: "λ", 5: "λΉλ°©μΈ", 6: "λΉλ°©μΈ/λλ λ¦Ό", 7: "λλ λ¦Ό"}
pty_str = pty_map.get(pty, str(pty))
print(f" π‘οΈ κΈ°μ¨: {t1h} β")
print(f" π§ μ΅λ: {reh} %")
print(f" π¬οΈ νμ: {wsd} m/s")
print(f" β κ°μ: {pty_str}")
if t1h < 0:
print(" π₯Ά κ²°λ‘ : μνκΆμ
λλ€. λ§€μ° μΆ₯μ΅λλ€.")
elif t1h < 5:
print(" π§₯ κ²°λ‘ : μμν©λλ€. λκΊΌμ΄ μΈν¬κ° νμν©λλ€.")
else:
print(" π κ²°λ‘ : λ§μ΄ μΆ₯μ§λ μμ΅λλ€.")
except (KeyError, ValueError) as e:
print(f"β οΈ λ°μ΄ν° νμ± μ€ν¨: {e}")
print(f"Raw: {result_str[:200]}...")
except Exception as e:
print(f"β Error: {e}")
if __name__ == "__main__":
asyncio.run(main())