根据前端传过来的前端传递过来的开始时间和结束时间参数 筛选创建时间在开始时间和结束时间区间的数据 修改后端写法def get_bugs_data(): api_url = "https://api.tapd.cn/bugs" api_headers = {"Authorization": "#", "content-type": "application/json"}iterations_url = "https:/"count_url ="https://at" params_count = {"status": "closed","workspace_id": 41571821, } # 发送请求,获取缺陷总数 response = requests.get(count_url, params=params_count, headers=api_headers) if response.status_code == 200: total_bug = response.json()total_count = total_bug['data']['count'] print(total_count) else: print("Error: Failed to retrieve count. Status code: ", response.status_code) start_time = request.get('start_time') end_time = request.get('end_time') start_time =datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S') end_time = datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S') bug_list = [] for i in range(1,total_count//200): params = {"limit": 200, "status": "closed", "workspace_id": 41571821, "page": i } response = requests.get(api_url, params=params, headers=api_headers) if response.status_code == 200: res = response.json() for bug_item in res['data']: if bug_item['Bug']['fixer'] and bug_item['Bug']['fixer'] in white_name:bug_data_dict = {"bug_title": bug_item['Bug']['title'], "bug_created": bug_item['Bug']['created'], "bug_fixer": bug_item['Bug']['fixer'], "bug_resolved": bug_item['Bug']['resolved'], "bug_url": f"https://www.tapd.cn/41571821/bugtrace/bugs/view?bug_id={bug_item['Bug']['id']}" } params_iteration = {"limit": 200, "workspace_id": 41571821, "id": bug_item['Bug']['iteration_id'] }response =requests.get(iterations_url, params=params_iteration, headers=api_headers)if response.status_code == 200: iterations = response.json() iteration_name = iterations['data'][0]['Iteration']['name'] bug_data_dict['iteration_name'] = iteration_name bug_list.append(bug_data_dict) else: print("Error: Failed to retrieve iterations. Status code: ", response.status_code) return {"code": 200, "msg": "成功", "data": bug_list}
时间: 2023-06-25 17:04:41 浏览: 232
laydate如何根据开始时间或者结束时间限制范围
可以将代码中的bug数据筛选部分修改如下:
```python
bug_list = []
for i in range(1, total_count//200 + 2):
params = {"limit": 200, "status": "closed", "workspace_id": 41571821, "page": i}
response = requests.get(api_url, params=params, headers=api_headers)
if response.status_code == 200:
res = response.json()
for bug_item in res['data']:
created_time = datetime.strptime(bug_item['Bug']['created'], '%Y-%m-%d %H:%M:%S')
if start_time <= created_time <= end_time:
if bug_item['Bug']['fixer'] and bug_item['Bug']['fixer'] in white_name:
bug_data_dict = {"bug_title": bug_item['Bug']['title'],
"bug_created": bug_item['Bug']['created'],
"bug_fixer": bug_item['Bug']['fixer'],
"bug_resolved": bug_item['Bug']['resolved'],
"bug_url": f"https://www.tapd.cn/41571821/bugtrace/bugs/view?bug_id={bug_item['Bug']['id']}"}
params_iteration = {"limit": 200, "workspace_id": 41571821, "id": bug_item['Bug']['iteration_id']}
response = requests.get(iterations_url, params=params_iteration, headers=api_headers)
if response.status_code == 200:
iterations = response.json()
iteration_name = iterations['data'][0]['Iteration']['name']
bug_data_dict['iteration_name'] = iteration_name
bug_list.append(bug_data_dict)
else:
print("Error: Failed to retrieve iterations. Status code: ", response.status_code)
else:
print("Error: Failed to retrieve bugs. Status code: ", response.status_code)
return {"code": 200, "msg": "成功", "data": bug_list}
```
在每个缺陷被处理时,将其创建时间转换为datetime对象,然后与开始时间和结束时间进行比较。如果创建时间在时间范围内,则将该缺陷加入到结果列表中。
阅读全文