Alptraum commited on
Commit
c5cc60e
·
verified ·
1 Parent(s): eee6546

Update app.py

Browse files

weather search changed to duckgo

Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -68,14 +68,15 @@ def get_movie_recommendation(mood: str, location: str, user_preferences: dict) -
68
  - "link" (str): A link to more information about the movie.
69
  """
70
 
71
- # Fetch weather data from a free API (wttr.in)
72
- weather_url = f"https://wttr.in/{location}?format=%C"
73
- response = requests.get(weather_url)
 
74
 
75
- if response.status_code != 200 or "Unknown location" in response.text:
76
- return {"error": f"Could not fetch weather data for {location}."}
77
 
78
- weather_condition = response.text.strip().lower()
79
 
80
  # Define mood & weather-based genre mapping
81
  genre_mapping = {
 
68
  - "link" (str): A link to more information about the movie.
69
  """
70
 
71
+ # Fetch weather data using DuckDuckGo search
72
+ search_tool = DuckDuckGoSearchTool()
73
+ weather_query = f"current weather in {location}"
74
+ weather_results = search_tool.search(weather_query)
75
 
76
+ if not weather_results:
77
+ return {"error": "Could not fetch weather data."}
78
 
79
+ weather_condition = weather_results[0].get("snippet", "").lower()
80
 
81
  # Define mood & weather-based genre mapping
82
  genre_mapping = {