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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
| from datetime import datetime, timedelta
| from utils.date_utils import DateUtils
| from .base_request import my_Request
| import json
| from utils.log_utils import LogUtils
|
|
| def fetch_duty_company() -> list:
| """
| 获取运维商信息
|
| Returns:
| [
| {
| "GroupName": "金山区",
| "TypeID": 3,
| "CheckTime": null,
| "TypeName": "码头",
| "RingID": 4,
| "EngineeringStage": null,
| "Address": "漫华路8号",
| "TroubleNum": null,
| "Linkman": "季工",
| "SName": "环装",
| "Code": "SHHBZB025-SH021041-01",
| "EndDate": "1900-01-01 00:00:00",
| "InsertTime": null,
| "Name": "漕泾电厂码头",
| "GroupID": 16,
| "RingName": "外环外",
| "BeginDate": "1900-01-01 00:00:00",
| "IsOnline": 1,
| "DutyCompanyID": 1,
| "KIndex": 0.0039,
| "Phone": "13816791072",
| "ID": 515,
| "IsTrouble": 0,
| "MNCode": "HJZB0JS0300246"
| }
| ]
| """
| data = {
| 'online': 1,
| 'div': 16,
| 'type': '1,4,3,5'
| }
| url = my_Request.base_url+'/DustManger/ReportData/RunstatusCount'
| res = my_Request.post(url, data)
| if res == False:
| return False
| elif res.text == '':
| LogUtils.error("cookie失效, 站点基本信息未获取到")
| return []
| else:
| return json.loads(res.text)
|
|
| def fetch_site_info() -> list:
| """
| 获取监测站点基本信息
|
|
| Returns:
| [
| {
| "Active": 1,
| "Address": "上海市金山区亭林镇周栅村荡新7组1056号",
| "Code": "HMHB00087",
| "DustValue": 0.065,
| "DutyCompany": "上海泓旻环保科技有限公司",
| "DutyCompanyID": 25,
| "GroupID": 16,
| "GroupName": "金山区",
| "ID": 41024,
| "IsOnline": 1,
| "Name": "上海阜阜建材有限公司",
| "IsTrouble": 0,
| "LST": "2023-10-27 08:15:00",
| "RingName": "外环外",
| "MNCode": "HMHB0JS0300084",
| "TypeName": "码头",
| "TypeID": 3,
| "NoiseValue": "68.9",
| "RingID": 4
| }
| ]
| """
|
| # 获取运维商信息
| companys = fetch_duty_company()
| if companys == False:
| return False
|
| # 获取前天0点
| time = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=2)
| time_str = DateUtils.time_to_str(time)
| data = {
| 'isOnline': 1,
| 'div': 16,
| 'sTime': time_str,
| 'type': '1,4,3,5'
| }
|
| url_site_info = my_Request.base_url+'/DustManger/ReportData/MonitorOnlineSite'
| res = my_Request.post(url_site_info, data)
| if res == False:
| return False
| elif res.text == '':
| return []
| else:
| sites = json.loads(res.text)
| # 替换运维商别名
|
| def f(x):
| for c in companys:
| if c["ID"] == x["ID"]:
| x["BeginDate"] = c["BeginDate"]
| x["DutyCompany"] = c["SName"]
| x["EndDate"] = c["EndDate"]
| x["EngineeringStage"] = c["EngineeringStage"]
| x["IsTrouble"] = c["IsTrouble"]
| x["KIndex"] = c["KIndex"]
| x["Linkman"] = c["Linkman"]
| x["Phone"] = c["Phone"]
| x["TroubleNum"] = c["TroubleNum"]
| break
| return x
| sites = map(f, sites)
| return sites
|
|