diff --git a/Web_app/pages/Favorite_Movie.py b/Web_app/pages/Favorite_Movie.py new file mode 100644 index 00000000..bd15977f --- /dev/null +++ b/Web_app/pages/Favorite_Movie.py @@ -0,0 +1,325 @@ +import streamlit as st +import requests +import time +from datetime import datetime +import json + +# Initialize session state for favorites +if "favorites" not in st.session_state: + st.session_state.favorites = set() + +# TMDB API Configuration +API_KEY = "Imdb_api_key" +BASE_URL = "https://api.themoviedb.org/3" + + +def fetch_movies(list_type="trending"): + """Fetch movies from TMDB API""" + if list_type == "trending": + url = f"{BASE_URL}/trending/movie/week?api_key={API_KEY}" + else: + url = f"{BASE_URL}/movie/popular?api_key={API_KEY}" + + try: + response = requests.get(url) + return response.json()["results"] if response.status_code == 200 else [] + except: + st.error("Failed to fetch movies") + return [] + + +# Page Configuration +st.set_page_config(page_title="Movie Collection", page_icon="🎬", layout="wide") + +# Custom CSS for the new compact design +st.markdown( + """ + + """, + unsafe_allow_html=True, +) + +# Header +st.markdown( + """ +
+

🎬 Movie Collection

+

Discover and collect your favorite movies

+
+ """, + unsafe_allow_html=True, +) + +# Filter Section +col1, col2, col3 = st.columns([1, 1, 1]) +with col1: + show_favorites = st.checkbox("Show Favorites", key="show_favorites") +with col2: + sort_by = st.selectbox( + "Sort by", ["Rating", "Release Date", "Title"], key="sort_by" + ) +with col3: + list_type = st.selectbox("List Type", ["Trending", "Popular"], key="list_type") + +# Fetch and process movies +movies = fetch_movies(list_type.lower()) + +# Filter favorites if needed +if show_favorites: + movies = [m for m in movies if m["id"] in st.session_state.favorites] + +# Sort movies +if sort_by == "Rating": + movies.sort(key=lambda x: x["vote_average"], reverse=True) +elif sort_by == "Release Date": + movies.sort(key=lambda x: x["release_date"], reverse=True) +else: + movies.sort(key=lambda x: x["title"]) + +# Display movies +if not movies: + st.markdown( + """ +
+

No movies found

+

Try adjusting your filters or check back later for new movies.

+
+ """, + unsafe_allow_html=True, + ) +else: + for movie in movies: + # Create columns for layout + movie_id = movie["id"] + is_favorite = movie_id in st.session_state.favorites + + # Movie card HTML + st.markdown( + f""" +
+
+ {movie['title']} +
+
+
+
{movie['title']}
+
+ {movie['release_date'][:4]} + ★ {movie['vote_average']:.1f} +
+
+
+
+ {'❤️' if is_favorite else '🤍'} + +
+
+ """, + unsafe_allow_html=True, + ) + + # Toggle favorite button + if st.button( + f"{'Remove from' if is_favorite else 'Add to'} Favorites", + key=f"toggle_{movie_id}", + ): + if is_favorite: + st.session_state.favorites.remove(movie_id) + else: + st.session_state.favorites.add(movie_id) + st.experimental_rerun() + +# JavaScript for interactivity +st.markdown( + """ + +