删除多余output,优化api调用函数

This commit is contained in:
Vege1imkafig 2025-07-04 21:31:54 +08:00
parent 28a8cd0965
commit 0754804992
26 changed files with 20 additions and 61 deletions

View File

@ -505,18 +505,14 @@ async def generate_report(base_info, baogao_info):
print(await search_and_replace(output_dir, 'baogao_date', baogao_date.split(' ')[0]))
print(await search_and_replace(output_dir, jiegou_xuhao, num_to_chinese[head_num]))
def main():
json_data1 = {
"turbine_id" : "183463dbf40d9278549a76b82b175dd9",
}
json_data2 = {
'shengcheng_dir': r"D:\work\Report_Generate_Server\output",
'muban_dir': r"D:\work\Report_Generate_Server\muban",
'shengcheng_dir': r".\output",
'muban_dir': r".\muban",
}
asyncio.run(generate_report(json_data1,json_data2))
print('文档生成完毕')

Binary file not shown.

Binary file not shown.

View File

@ -1,79 +1,42 @@
import requests
import json
from tools.API import *
def get_project_info(projectId):
projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId)
def get_data(url, data_type="data", params=None):
headers = {
"content_type": "application/x-www-form-urlencoded"
}
try:
response = requests.get(projecturl, headers=headers)
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = json.loads(response.text)
print(f"获取到项目的数据:{data}")
return data["data"]
print(f"获取到数据:{data}")
return data.get(data_type)
else:
print(f"获取项目{projectId}数据失败,状态码:{response.status_code}")
print(f"请求数据失败,状态码:{response.status_code}")
return None
except Exception as e:
print(f"获取项目{projectId}数据失败,异常:{e}")
print(f"请求数据失败,异常:{e}")
return None
def get_project_info(projectId):
projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId)
return get_data(projecturl, "data")
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
return get_data(jizuurl, "data")
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
result = get_data(jizuurl, "rows", params)
return result[0] if result else 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
return get_data(weatherurl, "data")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.