30 lines
979 B
Python
30 lines
979 B
Python
import json
|
|
import re
|
|
|
|
# 读取 joj3_result.json 文件内容
|
|
with open("joj3_result.json", "r", encoding="utf-8") as file:
|
|
json_data = file.read()
|
|
|
|
# 解析 JSON 数据
|
|
data = json.loads(json_data)
|
|
|
|
# 定义正则表达式以提取 diff 代码块
|
|
diff_pattern = re.compile(r"```diff\n(.*?)\n```", re.DOTALL)
|
|
|
|
# 遍历 "run" 的 results
|
|
for run in data:
|
|
if run["name"] == "run":
|
|
results = run["results"]
|
|
for result_index, result in enumerate(results):
|
|
comment = result.get("comment", "")
|
|
matches = diff_pattern.findall(comment)
|
|
|
|
if matches:
|
|
print(f"Result {result_index + 1} diff blocks:")
|
|
for i, diff in enumerate(matches):
|
|
# 将 \n 替换为实际换行符
|
|
formatted_diff = diff.replace("\\n", "\n")
|
|
print(f"```diff\n{formatted_diff}\n```\n")
|
|
else:
|
|
print(f"Result {result_index + 1}: the same\n")
|