-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·46 lines (31 loc) · 1.15 KB
/
app.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import re
import requests
from bs4 import BeautifulSoup
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return get_temp()
def get_temp():
url = "http://hqzx.shmtu.edu.cn/cellphone/getHotWater"
payload = {}
headers = {}
response = requests.request("GET", url, headers=headers, data=payload)
soup = BeautifulSoup(response.text, "lxml")
ul_node = soup.select("ul")[0]
result_data = {}
for temp_node in ul_node.select("li > a > div"):
water_temperature = temp_node.select("div")[0].text
water_level = temp_node.select("div .stage")[0].text
building_number = temp_node.select("span")[0].text
water_temperature = (
float(re.findall(r"\d+\.?\d*", water_temperature)[0]))
water_level = (float(re.findall(r"\d+\.?\d*", water_level)[0]))
building_number = (int(re.findall(r"\d+", building_number)[0]))
result_data[building_number] = {
"temp": water_temperature,
"level": water_level
}
return result_data
if __name__ == '__main__':
print(get_temp())