내 프로젝트 3: Python + Streamlit으로 날씨 앱 만들기

발행: (2025년 12월 1일 오전 07:26 GMT+9)
3 min read
원문: Dev.to

Source: Dev.to

1. Project Overview

  • 도시 이름 입력
  • wttr.in을 사용해 실시간 날씨 가져오기
  • 온도, 상태, 습도 확인
  • 콘솔 스크립트(weather.py) 또는 Streamlit 웹 UI(weather_streamlit.py)로 제공

간단하고 깔끔하며 유용함 — 파이썬 연습에 딱 맞는 프로젝트.

2. API Used: wttr.in

wttr.in을 선택한 이유:

  • 회원가입이 필요 없음
  • JSON 반환이 간편함
  • 빠른 프로젝트에 적합

3. Console Version (weather.py)

Key Features

  • requests 라이브러리를 이용해 날씨 요청
  • 온도, 날씨 설명, 습도 표시
  • 오류를 우아하게 처리

Code

import requests

city = input("Enter city name: ")

url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)

if response.status_code != 200:
    print("Error fetching weather data.")
    exit()

data = response.json()
current = data["current_condition"][0]

print("=== Weather Report ===")
print("City:", city)
print("Temperature:", current["temp_C"], "°C")
print("Weather:", current["weatherDesc"][0]["value"])
print("Humidity:", current["humidity"], "%")

4. Streamlit Web Version (weather_streamlit.py)

Why Streamlit?

  • 깔끔한 웹 UI
  • 사용자 친화적인 도시 입력
  • 명확한 오류 메시지
  • 스타일이 적용된 날씨 데이터 출력

Code

import streamlit as st
import requests

st.title("🌤️ Sabin's Weather App")

city = st.text_input("Enter city name:", "Chur")

if st.button("Check Weather"):
    url = f"https://wttr.in/{city}?format=j1"
    response = requests.get(url)

    if response.status_code != 200:
        st.error("Error fetching weather data.")
    else:
        data = response.json()
        current = data["current_condition"][0]

        temp = current["temp_C"]
        desc = current["weatherDesc"][0]["value"]
        humidity = current["humidity"]

        st.subheader(f"Weather in {city}")
        st.write(f"🌡 Temperature: **{temp}°C**", unsafe_allow_html=True)
        st.write(f"☁ Condition: **{desc}**", unsafe_allow_html=True)
        st.write(f"💧 Humidity: **{humidity}%**", unsafe_allow_html=True)

5. How to Run

Console Version

python3 weather.py

Streamlit Version

pip install streamlit
streamlit run weather_streamlit.py

Streamlit이 자동으로 브라우저 창을 열어 웹 UI를 표시합니다.

6. What I Learned

  • requests를 이용한 API 요청 방법
  • JSON 응답 파싱
  • Streamlit으로 인터랙티브 UI 구축
  • 네트워크 응답에 대한 오류 처리
  • 콘솔 스크립트를 웹 앱으로 변환하는 과정

7. Future Improvements

  • 날씨 아이콘 추가
  • 시간별·주간 예보 표시
  • 다국어 지원
  • 배경 테마 추가(맑음, 흐림, 비)
  • 즐겨 찾는 도시 저장 기능
Back to Blog

관련 글

더 보기 »

창고 활용에 대한 종합 가이드

소개 창고는 근본적으로 3‑D 박스일 뿐입니다. Utilisation은 실제로 그 박스를 얼마나 사용하고 있는지를 측정하는 지표입니다. While logistics c...