CR commited on
Update app.py
Browse filestrying to isolate the first response in the result of the lat lon
app.py
CHANGED
|
@@ -23,15 +23,13 @@ def get_current_temperature(location: str)-> str: #it's import to specify the re
|
|
| 23 |
try:
|
| 24 |
# First we get the geocoding data to get the latitude and longitude of a location
|
| 25 |
geocoding_data = httpx.get('http://api.openweathermap.org/geo/1.0/direct?q={location}&limit=1&appid={OpenWeather_API_key}')
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
longitude = geocoding_data.lon
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error fetching data for location '{location}': {str(e)}"
|
| 31 |
try:
|
| 32 |
# Then we use that to get the current temperature in Fahrenheit
|
| 33 |
current_data = httpx.get('https://api.openweathermap.org/data/3.0/onecall?lat={latitude}&lon={longitude}&units={imperial}&appid={OpenWeather_API_key}')
|
| 34 |
-
print(f"current_data = '{current_data}'")
|
| 35 |
temperature = current_data.current.temp
|
| 36 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 37 |
except Exception as e:
|
|
|
|
| 23 |
try:
|
| 24 |
# First we get the geocoding data to get the latitude and longitude of a location
|
| 25 |
geocoding_data = httpx.get('http://api.openweathermap.org/geo/1.0/direct?q={location}&limit=1&appid={OpenWeather_API_key}')
|
| 26 |
+
latitude = geocoding_data.[0].lat
|
| 27 |
+
longitude = geocoding_data.[0].lon
|
|
|
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error fetching data for location '{location}': {str(e)}"
|
| 30 |
try:
|
| 31 |
# Then we use that to get the current temperature in Fahrenheit
|
| 32 |
current_data = httpx.get('https://api.openweathermap.org/data/3.0/onecall?lat={latitude}&lon={longitude}&units={imperial}&appid={OpenWeather_API_key}')
|
|
|
|
| 33 |
temperature = current_data.current.temp
|
| 34 |
return f"The current temperature in {location} is {temperature} degrees Fahrenheit."
|
| 35 |
except Exception as e:
|