Chintan Donda commited on
Commit
77a878e
·
1 Parent(s): 9d9579e

Fixing temperature information issue in Weather widget

Browse files
Files changed (1) hide show
  1. 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
- headers = {
75
- 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
76
- }
77
- response = requests.get(
78
- f'https://www.google.com/search?q={city}&oq={city}&aqs=chrome.0.35i39l2j0l4j46j69i60.6128j1j7&sourceid=chrome&ie=UTF-8', headers=headers)
79
-
80
- soup = bs(response.text, 'html.parser')
81
- location = soup.select('#wob_loc')[0].getText().strip()
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