Zoro-147 commited on
Commit
c971d4c
·
verified ·
1 Parent(s): 30ce246

Update weather.py

Browse files
Files changed (1) hide show
  1. weather.py +23 -24
weather.py CHANGED
@@ -1,25 +1,24 @@
1
- import requests
2
- import os
3
-
4
- WEATHER_API_KEY = os.getenv("WEATHER_API_KEY")
5
-
6
- def get_current_weather(location: str) -> str:
7
- url = "http://api.weatherapi.com/v1/current.json"
8
- params = {
9
- "key": WEATHER_API_KEY,
10
- "q": location,
11
- "aqi": "no"
12
- }
13
- try:
14
- response = requests.get(url, params=params, timeout=10)
15
- response.raise_for_status()
16
- data = response.json()
17
- location = data["location"]["name"]
18
- temp_c = data["current"]["temp_c"]
19
- condition = data["current"]["condition"]["text"]
20
- humidity = data["current"]["humidity"]
21
- wind_kph = data["current"]["wind_kph"]
22
- return (f"Weather in {location}: {temp_c}°C, {condition}, "
23
- f"Humidity: {humidity}%, Wind: {wind_kph} km/h")
24
- except Exception as e:
25
  return f"Error fetching weather: {str(e)}"
 
1
+ import requests
2
+ import os
3
+
4
+ WEATHER_API_KEY = os.getenv("WEATHER_API_KEY")
5
+
6
+ def get_current_weather(location: str) -> str:
7
+ url = "https://weatherapi-com.p.rapidapi.com/current.json?q=53.1%2C-0.13"
8
+ params = {
9
+ "key": WEATHER_API_KEY,
10
+ "q": location,
11
+ }
12
+ try:
13
+ response = requests.get(url, params=params, timeout=10)
14
+ response.raise_for_status()
15
+ data = response.json()
16
+ location = data["location"]["name"]
17
+ temp_c = data["current"]["temp_c"]
18
+ condition = data["current"]["condition"]["text"]
19
+ humidity = data["current"]["humidity"]
20
+ wind_kph = data["current"]["wind_kph"]
21
+ return (f"Weather in {location}: {temp_c}°C, {condition}, "
22
+ f"Humidity: {humidity}%, Wind: {wind_kph} km/h")
23
+ except Exception as e:
 
24
  return f"Error fetching weather: {str(e)}"