내 프로젝트 4: 영화 검색 앱 (Python + Streamlit)
발행: (2025년 12월 3일 오전 07:53 GMT+9)
3 min read
원문: Dev.to
Source: Dev.to
🧱 1. 프로젝트 개요
Movie Search App은 다음을 할 수 있습니다:
- 영화 제목 입력
- 상세 영화 정보 가져오기
- 포스터, 장르, 줄거리, 평점 보기
- 콘솔 또는 Streamlit 웹 인터페이스 중 선택 가능
📂 2. 프로젝트 구조
movie_app/
│
├── movie_app.py # 콘솔 버전
├── movie_app_streamlit.py # Streamlit 버전
└── README.md # (선택 사항)
🌐 3. 사용 API: OMDb API
OMDb는 무료 API 키가 필요합니다. 여기서 발급받으세요:
🔗 https://www.omdbapi.com/apikey.aspx
🖥️ 4. 콘솔 버전 (movie_app.py)
주요 기능
requests를 이용해 영화 데이터 가져오기- 잘못된 제목을 우아하게 처리
- 핵심 영화 상세 정보 출력
📌 코드
import requests
API_KEY = "YOUR_API_KEY" # Put your OMDb API key here
title = input("Movie title: ")
url = f"https://www.omdbapi.com/?t={title}&apikey={API_KEY}"
response = requests.get(url)
if response.status_code != 200:
print("Error fetching data.")
exit()
data = response.json()
if data["Response"] == "False":
print("Movie not found.")
exit()
print("=== Movie Info ===")
print("Title:", data["Title"])
print("Year:", data["Year"])
print("Genre:", data["Genre"])
print("Plot:", data["Plot"])
print("Rating:", data["imdbRating"])
🌤️ 5. Streamlit 버전 (movie_app_streamlit.py)
추가 기능
- 포스터 이미지 표시
- 깔끔하게 포맷된 UI 출력
- 오류 / 검색 결과 없음 처리
📌 코드
import streamlit as st
import requests
st.title("🎬 Sabin's Movie Search App")
API_KEY = "YOUR_API_KEY"
title = st.text_input("Enter movie title:", "Inception")
if st.button("Search"):
url = f"https://www.omdbapi.com/?t={title}&apikey={API_KEY}"
response = requests.get(url)
if response.status_code != 200:
st.error("Error fetching data.")
else:
data = response.json()
if data["Response"] == "False":
st.warning("Movie not found.")
else:
st.subheader(f"{data['Title']} ({data['Year']})")
if data["Poster"] != "N/A":
st.image(data["Poster"], width=300)
else:
st.info("No poster available.")
st.write(f"Genre: {data['Genre']}")
st.write(f"Rating: ⭐ {data['imdbRating']}")
st.write(f"Plot: {data['Plot']}")
⚙️ 6. 실행 방법
✔ 콘솔 버전
python3 movie_app.py
✔ Streamlit 버전
pip install streamlit
streamlit run movie_app_streamlit.py
📚 7. 배운 점
- 인증이 필요한 API 사용법
- 누락된 데이터에 대한 오류 처리
- Streamlit에서 이미지 표시 방법
- CLI와 웹 앱의 차이점
🔧 8. 향후 개선 사항
- 정확한 제목 대신 키워드 검색 지원
- 비슷한 영화 또는 추천 영화 표시
- 즐겨찾는 영화 저장 기능
- Rotten Tomatoes / Metacritic 평점 추가
- 다크 모드 UI