-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweather.py
28 lines (22 loc) · 922 Bytes
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
from bs4 import BeautifulSoup
class Weather:
@staticmethod
def get_weather_today(city: str = "санкт-петербург") -> list:
http = "https://sinoptik.com.ru/погода-" + city
b = BeautifulSoup(requests.get(http).text, "html.parser")
p3 = b.select('.temperature .p3')
weather1 = p3[0].getText()
p4 = b.select('.temperature .p4')
weather2 = p4[0].getText()
p5 = b.select('.temperature .p5')
weather3 = p5[0].getText()
p6 = b.select('.temperature .p6')
weather4 = p6[0].getText()
result = ''
result = result + ('Утром :' + weather1 + ' ' + weather2) + '\n'
result = result + ('Днём :' + weather3 + ' ' + weather4) + '\n'
temp = b.select('.rSide .description')
weather = temp[0].getText()
result = result + weather.strip()
return result