aniketkno commited on
Commit
b0ad9cd
·
verified ·
1 Parent(s): f771494

Update tools/weather.py

Browse files
Files changed (1) hide show
  1. tools/weather.py +7 -7
tools/weather.py CHANGED
@@ -61,16 +61,16 @@ class WeatherForecast(Tool):
61
 
62
  # This approach is less reliable and might have rate limits.
63
  # It's suitable for basic use cases but not for production.
64
-
65
- geocoding_url = "https://nominatim.openstreetmap.org/search" # No API Key needed
66
- params = {
67
- "q": city_name,
68
- "format": "json",
69
- "limit": 3
70
  }
71
 
 
 
 
 
72
  try:
73
- response = requests.get(geocoding_url, params=params)
74
  response.raise_for_status()
75
  geocoding_data = response.json()
76
  print(geocoding_data)
 
61
 
62
  # This approach is less reliable and might have rate limits.
63
  # It's suitable for basic use cases but not for production.
64
+ headers = {
65
+ 'User-Agent': 'MyGeocodingApp/1.0 (youremail@example.com)'
 
 
 
 
66
  }
67
 
68
+ city_name = city_name.replace(" ", "+")
69
+ base_url = "https://nominatim.openstreetmap.org/search"
70
+ full_url = f"{base_url}?q={requests.utils.quote(city_name)}&format=json&limit=5"
71
+
72
  try:
73
+ response = requests.get(geocoding_url, headers=headers)
74
  response.raise_for_status()
75
  geocoding_data = response.json()
76
  print(geocoding_data)