auto_generated_movies.html

import requests import json # URL to fetch the movie JSON json_url = "https://vidsrc.vip/list/movie.json" # Output file for generated HTML output_file = "auto_movies.html" def fetch_movie_data(): """Fetch movie data from the JSON URL.""" try: response = requests.get(json_url) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: print(f"Error fetching data: {e}") return [] def generate_html(movies): """Generate HTML content for the movies.""" html_content = """ Auto-Generated Movies

Auto-Generated Movies

""" # Loop through movies to generate content for movie in movies: title = movie.get("title", "Unknown Title") imdb_id = movie.get("imdb_id", "") poster = movie.get("poster", "https://via.placeholder.com/150") year = movie.get("year", "N/A") genre = movie.get("genre", "N/A") embed_url = f"https://vidsrc.xyz/embed/movie?imdb={imdb_id}" html_content += f"""
{title}

{title}

Year: {year}

Genre: {genre}

View on IMDb

""" html_content += """ """ return html_content def save_html(content): """Save the generated HTML content to a file.""" try: with open(output_file, "w", encoding="utf-8") as file: file.write(content) print(f"HTML file saved as {output_file}") except IOError as e: print(f"Error saving file: {e}") def main(): # Step 1: Fetch data movies = fetch_movie_data() # Step 2: Generate HTML content if movies: html_content = generate_html(movies) # Step 3: Save to file save_html(html_content) else: print("No movies found.") if __name__ == "__main__": main()

Post a Comment

Previous Post Next Post