Alptraum commited on
Commit
a0222c7
·
verified ·
1 Parent(s): 30d1f43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -13,7 +13,25 @@ from imdb import Cinemagoer
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
 
 
17
  def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -> dict:
18
  """
19
  Recommend a movie based on the user's mood, current weather at the given location,
@@ -59,9 +77,8 @@ def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -
59
  if key in weather_condition:
60
  recommended_genres.append(weather_mapping[key])
61
 
62
- # Initialize IMDbPY
63
- ia = Cinemagoer()
64
 
 
65
  # Fetch top movies from IMDb by genre
66
  genre_movies = []
67
  for genre in recommended_genres:
 
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
 
16
+ def fetch_movie_from_omdb(genre: str):
17
+ api_key = "59341a1e"
18
+ url = f"http://www.omdbapi.com/?i=tt3896198&apikey=59341a1e"
19
+
20
+ response = requests.get(url)
21
+ if response.status_code != 200:
22
+ return {"error": "Failed to fetch movie data."}
23
+
24
+ data = response.json()
25
+ if "Search" not in data:
26
+ return {"error": "No movies found for this genre."}
27
 
28
+ best_movie = data["Search"][0] # Pick the first result
29
+ return {
30
+ "title": best_movie["Title"],
31
+ "year": best_movie["Year"],
32
+ "genre": genre,
33
+ "imdb_id": best_movie["imdbID"]
34
+ }
35
  def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -> dict:
36
  """
37
  Recommend a movie based on the user's mood, current weather at the given location,
 
77
  if key in weather_condition:
78
  recommended_genres.append(weather_mapping[key])
79
 
 
 
80
 
81
+ best_movie = fetch_movie_from_omdb(recommended_genres[0])
82
  # Fetch top movies from IMDb by genre
83
  genre_movies = []
84
  for genre in recommended_genres: