-
Notifications
You must be signed in to change notification settings - Fork 0
/
wAPI.py
29 lines (26 loc) · 1.09 KB
/
wAPI.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
29
from bs4 import BeautifulSoup
from urllib.request import urlopen
import datetime
def get_next_hours():
url = "https://www.wetter.de/deutschland/wetter-leipzig-18232916.html"
content = urlopen(url).read()
#print(content)
soup = BeautifulSoup(content,features = "html.parser")
time = int(str(datetime.datetime.now().time())[:2])
arounds = ""
for i in range(time,time+3):
try:
arounds+=str(soup.find("div",{"data-id":str(i)}).get_text())[-3:-1]+";"+str(soup.find("div",{"data-id":str(i)}).find("img").get("title"))+"\n"
except:
arounds+="0;no data\n"
pass # a day only has 24 hours.
print(arounds)
return arounds
def get_max_min_temp():
url = "https://www.wetter.de/deutschland/wetter-leipzig-18232916.html"
content = urlopen(url).read()
# print(content)
soup = BeautifulSoup(content, features="html.parser")
max = soup.find("div", {"class": "weather-daybox__minMax__max"}).get_text()[:2]
min = soup.find("div", {"class": "weather-daybox__minMax__min"}).get_text()[:2]
return str(max)+";"+str(min)+"\n"