79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
|
import requests
|
||
|
import json
|
||
|
from tools.API import *
|
||
|
def get_project_info(projectId):
|
||
|
projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId)
|
||
|
headers = {
|
||
|
"content_type" : "application/x-www-form-urlencoded"
|
||
|
}
|
||
|
try:
|
||
|
response = requests.get(projecturl, headers=headers)
|
||
|
if response.status_code == 200:
|
||
|
data = json.loads(response.text)
|
||
|
print(f"获取到项目的数据:{data}")
|
||
|
return data["data"]
|
||
|
else:
|
||
|
print(f"获取项目{projectId}数据失败,状态码:{response.status_code}")
|
||
|
return None
|
||
|
except Exception as e:
|
||
|
print(f"获取项目{projectId}数据失败,异常:{e}")
|
||
|
return None
|
||
|
|
||
|
def get_jizu_info(turbineId):
|
||
|
jizuurl = DTURL + GETJIZUINFO.format(turbineId=turbineId)
|
||
|
headers = {
|
||
|
"content_type" : "application/x-www-form-urlencoded"
|
||
|
}
|
||
|
try:
|
||
|
response = requests.get(jizuurl, headers=headers)
|
||
|
if response.status_code == 200:
|
||
|
data = json.loads(response.text)
|
||
|
print(f"获取到机组的数据:{data}")
|
||
|
return data["data"]
|
||
|
else:
|
||
|
print(f"获取项目{turbineId}数据失败,状态码:{response.status_code}")
|
||
|
return None
|
||
|
except Exception as e:
|
||
|
print(f"获取项目{turbineId}数据失败,异常:{e}")
|
||
|
return None
|
||
|
|
||
|
def get_jizu_shigong_info(turbineId):
|
||
|
jizuurl = DTURL + GETSHIGONGINFO
|
||
|
headers = {
|
||
|
"content_type" : "application/x-www-form-urlencoded"
|
||
|
}
|
||
|
params = {
|
||
|
"rows" : {
|
||
|
"turbineId" : turbineId
|
||
|
}
|
||
|
}
|
||
|
try:
|
||
|
response = requests.get(jizuurl, headers=headers, params=params)
|
||
|
if response.status_code == 200:
|
||
|
data = json.loads(response.text)
|
||
|
print(f"获取到机组施工的数据:{data}")
|
||
|
return data["rows"][0]
|
||
|
else:
|
||
|
print(f"获取项目{turbineId}施工数据失败,状态码:{response.status_code}")
|
||
|
return None
|
||
|
except Exception as e:
|
||
|
print(f"获取项目{turbineId}施工数据失败,异常:{e}")
|
||
|
return None
|
||
|
|
||
|
def get_weather(weatherid):
|
||
|
weatherurl = DTURL + GETWEATHERINFO.format(weatherCode=weatherid)
|
||
|
headers = {
|
||
|
"content_type" : "application/x-www-form-urlencoded"
|
||
|
}
|
||
|
try:
|
||
|
response = requests.get(weatherurl, headers=headers)
|
||
|
if response.status_code == 200:
|
||
|
data = json.loads(response.text)
|
||
|
print(f"获取到天气数据:{data}")
|
||
|
return data["data"]
|
||
|
else:
|
||
|
print(f"获取天气{weatherid}数据失败,状态码:{response.status_code}")
|
||
|
return None
|
||
|
except Exception as e:
|
||
|
print(f"获取天气{weatherid}数据失败,异常:{e}")
|
||
|
return None
|