-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie_info.py
38 lines (29 loc) · 1021 Bytes
/
movie_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
import os
from dotenv import load_dotenv
load_dotenv()
def fetch_movie_data(movie_title):
base_url = "http://www.omdbapi.com/"
api_key = os.environ['omdb_api'] # If you have one. Not required for basic usage.
params = {
"t": movie_title,
"apikey": api_key, # Not required if you don't have an API key.
}
response = requests.get(base_url, params=params)
if response.status_code == 200:
return response.json()
else:
return None
# # Example usage
# movie_title = "Inception"
# movie_data = fetch_movie_data(movie_title)
# if movie_data is not None:
# print(f"Title: {movie_data['Title']}")
# print(f"Year: {movie_data['Year']}")
# print(f"Genre: {movie_data['Genre']}")
# print(f"Director: {movie_data['Director']}")
# print(f"Actors: {movie_data['Actors']}")
# print(f"Plot: {movie_data['Plot']}")
# else:
# print(f"Failed to fetch data for {movie_title}.")
# print(fetch_movie_data("Bhagam Bhag")['Genre'])