import requests import json from tools.API import * def get_data(url : str, data_type : str = "data", params : dict = None ) -> dict: headers = { "content_type": "application/x-www-form-urlencoded" } try: response = requests.get(url, headers=headers, params=params) if response.status_code == 200: data = json.loads(response.text) print(f"获取到数据:{data}") return data[data_type] else: print(f"请求数据失败,状态码:{response.status_code}") return None except Exception as e: print(f"请求数据失败,异常:{e}") return None def get_project_info(projectId : str) -> dict: projecturl = DTURL + GETPROJECTINFO.format(projectId=projectId) return get_data(projecturl, "data") def get_jizu_info(turbineId : str) -> dict: jizuurl = DTURL + GETJIZUINFO.format(turbineId=turbineId) return get_data(jizuurl, "data") def get_jizu_shigong_info(turbineId : str) -> dict: jizuurl = DTURL + GETSHIGONGINFO params = { "rows": { "turbineId": turbineId } } result = get_data(jizuurl, "rows", params) return result[0] if result else None def get_weather(weatherid : str) -> dict: weatherurl = DTURL + GETWEATHERINFO.format(weatherCode=weatherid) return get_data(weatherurl, "data") def get_part_list(turbineId : str) -> dict: parturl = DTURL + GETPARTLIST params = { "turbineId" : turbineId } result = get_data(parturl, params = params) result = [item["partId"] for item in result] print(f"获取到部件{result}") return result def get_picture(turbineId : str): """获取对应机组所有图片 Args: turbineId (str): 机组ID Return: list: 包含所有图片信息的列表(按部件分list) [ [ { "imageId": "字符串", "imageName": "字符串", "imagePath": "字符串", "partId": "字符串", "partName": "字符串", "imageResolution": "字符串", "focalDistance": "字符串/None", "shootingTime": "字符串/None", "cameraManufacturer": "字符串/None", "cameraModel": "字符串/None", "weather": "字符串/None", "weatherLabel": "字符串/None", "humidness": "数值/None", "temperature": "字符串/None", "windLevel": "数值/None", "shootingMethod": "字符串/None", "shootingMethodLabel": "字符串/None", "shootingDistance": "数值/None", "collectorName": "字符串/None", "imageType": "None", "imageTypeLabel": "None", "audioList": "None", "gps": "字符串/None" }, ... ], [ { // 相同结构的字典对象 }, ... ] ] """ picturerul = DTURL + GETPICTURELIST part_list = get_part_list(turbineId) result = [] for part_id in part_list: params = { "partId" : part_id, } result.append(get_data(picturerul, params = params)) return result