Spaces:
Runtime error
Runtime error
Chintan Donda
commited on
Commit
·
77a878e
1
Parent(s):
9d9579e
Fixing temperature information issue in Weather widget
Browse files- src/weather.py +9 -13
src/weather.py
CHANGED
@@ -70,18 +70,14 @@ class WEATHER:
|
|
70 |
):
|
71 |
city = city + " weather"
|
72 |
city = city.replace(" ", "+")
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
time = soup.select('#wob_dts')[0].getText().strip()
|
83 |
-
info = soup.select('#wob_dc')[0].getText().strip()
|
84 |
-
temperature = soup.select('#wob_tm')[0].getText().strip()
|
85 |
-
temperature = temperature + "°C"
|
86 |
|
87 |
return time, info, temperature
|
|
|
70 |
):
|
71 |
city = city + " weather"
|
72 |
city = city.replace(" ", "+")
|
73 |
+
|
74 |
+
soup = bs(
|
75 |
+
requests.get(f"https://www.google.com/search?q=weather+{city}").content,
|
76 |
+
'html.parser'
|
77 |
+
)
|
78 |
+
temperature = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'}).text.strip()
|
79 |
+
time = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text.split('\n')[0].strip()
|
80 |
+
time = ' '.join(time.split())
|
81 |
+
info = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text.split('\n')[1].strip()
|
|
|
|
|
|
|
|
|
82 |
|
83 |
return time, info, temperature
|