From 8ad2dca89a9e95b0ade4cc92c9e7fc2f0094a090 Mon Sep 17 00:00:00 2001 From: MIGHTY1o1 Date: Tue, 22 Oct 2024 04:21:09 +0530 Subject: [PATCH] add trending movies page --- Web_app/pages/Trending_Movies.py | 126 +++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Web_app/pages/Trending_Movies.py diff --git a/Web_app/pages/Trending_Movies.py b/Web_app/pages/Trending_Movies.py new file mode 100644 index 00000000..1ad75b25 --- /dev/null +++ b/Web_app/pages/Trending_Movies.py @@ -0,0 +1,126 @@ +import streamlit as st +import requests +import time + +# Your TMDB API key +API_KEY = "Imdb_api_key" + + +# Function to fetch trending movies from TMDB +def fetch_trending_movies(): + url = f"https://api.themoviedb.org/3/trending/movie/week?api_key={API_KEY}" + response = requests.get(url) + if response.status_code == 200: + return response.json()["results"] + else: + st.error("Failed to fetch data from TMDB.") + return [] + + +# Function to display loading spinner +def show_loading(): + with st.spinner("Fetching trending movies..."): + time.sleep(2) # Simulate a delay + return fetch_trending_movies() + + +# Configure the page +st.set_page_config( + page_title="Trending Movies", + page_icon="🎥", +) + +# Custom CSS for enhanced styling +st.markdown( + """ + +""", + unsafe_allow_html=True, +) + +# Header +st.markdown( + """ +

Trending Movies

+

Check out the latest trending movies of the week!

+ """, + unsafe_allow_html=True, +) + +# Fetch trending movies +trending_movies = show_loading() + +# Display the movies +if trending_movies: + # Create a container for movie cards + cols = st.columns(3) # Adjust the number of columns as needed + for i, movie in enumerate(trending_movies): + title = movie["title"] + overview = movie["overview"] + release_date = movie["release_date"] + poster_path = movie["poster_path"] + poster_url = f"https://image.tmdb.org/t/p/w500{poster_path}" + + # Create a card for each movie + with cols[i % 3]: # Cycle through columns + st.markdown( + f""" +
+ {title} +
{title}
+

{overview}

+
Release Date: {release_date}
+
+ """, + unsafe_allow_html=True, + ) +else: + st.warning("No trending movies available.")