Spaces:
Sleeping
Sleeping
updated weather response data
Browse files- tools/weather.py +85 -1
tools/weather.py
CHANGED
|
@@ -25,7 +25,91 @@ class WeatherTool(Tool):
|
|
| 25 |
location: A string representing a city (e.g., 'New York', 'Paris').
|
| 26 |
|
| 27 |
Returns:
|
| 28 |
-
A JSON blob with the current weather information in imperial units.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"""
|
| 30 |
# Validate that location contains only allowed characters: letters, digits, spaces, and hyphens
|
| 31 |
if not re.fullmatch(r'[A-Za-z0-9\s-]+', location):
|
|
|
|
| 25 |
location: A string representing a city (e.g., 'New York', 'Paris').
|
| 26 |
|
| 27 |
Returns:
|
| 28 |
+
A JSON blob with the current weather information in imperial units. The JSON blob should be formatted as a string. The response should be in the following format:
|
| 29 |
+
{
|
| 30 |
+
"coord": {
|
| 31 |
+
"lon": 7.367,
|
| 32 |
+
"lat": 45.133
|
| 33 |
+
},
|
| 34 |
+
"weather": [
|
| 35 |
+
{
|
| 36 |
+
"id": 501,
|
| 37 |
+
"main": "Rain",
|
| 38 |
+
"description": "moderate rain",
|
| 39 |
+
"icon": "10d"
|
| 40 |
+
}
|
| 41 |
+
],
|
| 42 |
+
"base": "stations",
|
| 43 |
+
"main": {
|
| 44 |
+
"temp": 284.2,
|
| 45 |
+
"feels_like": 282.93,
|
| 46 |
+
"temp_min": 283.06,
|
| 47 |
+
"temp_max": 286.82,
|
| 48 |
+
"pressure": 1021,
|
| 49 |
+
"humidity": 60,
|
| 50 |
+
"sea_level": 1021,
|
| 51 |
+
"grnd_level": 910
|
| 52 |
+
},
|
| 53 |
+
"visibility": 10000,
|
| 54 |
+
"wind": {
|
| 55 |
+
"speed": 4.09,
|
| 56 |
+
"deg": 121,
|
| 57 |
+
"gust": 3.47
|
| 58 |
+
},
|
| 59 |
+
"rain": {
|
| 60 |
+
"1h": 2.73
|
| 61 |
+
},
|
| 62 |
+
"clouds": {
|
| 63 |
+
"all": 83
|
| 64 |
+
},
|
| 65 |
+
"dt": 1726660758,
|
| 66 |
+
"sys": {
|
| 67 |
+
"type": 1,
|
| 68 |
+
"id": 6736,
|
| 69 |
+
"country": "IT",
|
| 70 |
+
"sunrise": 1726636384,
|
| 71 |
+
"sunset": 1726680975
|
| 72 |
+
},
|
| 73 |
+
"timezone": 7200,
|
| 74 |
+
"id": 3165523,
|
| 75 |
+
"name": "Province of Turin",
|
| 76 |
+
"cod": 200
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
The definitions of the JSON keys are:
|
| 80 |
+
coord.lon Longitude of the location
|
| 81 |
+
coord.lat Latitude of the location
|
| 82 |
+
weather.id Weather condition id
|
| 83 |
+
weather.main Group of weather parameters (Rain, Snow, Clouds etc.)
|
| 84 |
+
weather.description Weather condition within the group. Please find more here. You can get the output in your language. Learn more
|
| 85 |
+
weather.icon Weather icon id
|
| 86 |
+
base Internal parameter
|
| 87 |
+
main.temp Temperature. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
| 88 |
+
main.feels_like Temperature. This temperature parameter accounts for the human perception of weather. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
| 89 |
+
main.pressure Atmospheric pressure on the sea level, hPa
|
| 90 |
+
main.humidity Humidity, %
|
| 91 |
+
main.temp_min Minimum temperature at the moment. This is minimal currently observed temperature (within large megalopolises and urban areas). Please find more info here. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
| 92 |
+
main.temp_max Maximum temperature at the moment. This is maximal currently observed temperature (within large megalopolises and urban areas). Please find more info here. Unit Default: Kelvin, Metric: Celsius, Imperial: Fahrenheit
|
| 93 |
+
main.sea_level Atmospheric pressure on the sea level, hPa
|
| 94 |
+
main.grnd_level Atmospheric pressure on the ground level, hPa
|
| 95 |
+
visibility Visibility, meter. The maximum value of the visibility is 10 km
|
| 96 |
+
wind.speed Wind speed. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
| 97 |
+
wind.deg Wind direction, degrees (meteorological)
|
| 98 |
+
wind.gust Wind gust. Unit Default: meter/sec, Metric: meter/sec, Imperial: miles/hour
|
| 99 |
+
clouds.all Cloudiness, %
|
| 100 |
+
rain.1h(where available)Precipitation, mm/h. Please note that only mm/h as units of measurement are available for this parameter
|
| 101 |
+
snow.1h(where available) Precipitation, mm/h. Please note that only mm/h as units of measurement are available for this parameter
|
| 102 |
+
dt Time of data calculation, unix, UTC
|
| 103 |
+
sys.type Internal parameter
|
| 104 |
+
sys.id Internal parameter
|
| 105 |
+
sys.message Internal parameter
|
| 106 |
+
sys.country Country code (GB, JP etc.)
|
| 107 |
+
sys.sunrise Sunrise time, unix, UTC
|
| 108 |
+
sys.sunset Sunset time, unix, UTC
|
| 109 |
+
timezone Shift in seconds from UTC
|
| 110 |
+
id City ID. Please note that built-in geocoder functionality has been deprecated. Learn more here
|
| 111 |
+
name City name. Please note that built-in geocoder functionality has been deprecated. Learn more here
|
| 112 |
+
cod Internal parameter
|
| 113 |
"""
|
| 114 |
# Validate that location contains only allowed characters: letters, digits, spaces, and hyphens
|
| 115 |
if not re.fullmatch(r'[A-Za-z0-9\s-]+', location):
|