更新了保存的文档结构
This commit is contained in:
parent
3372572da2
commit
9f2d358c57
@ -71,7 +71,6 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
"ArticleJsonPath",
|
"ArticleJsonPath",
|
||||||
"OutputTxtPath",
|
"OutputTxtPath",
|
||||||
"PosterPath",
|
"PosterPath",
|
||||||
"CollagePath",
|
|
||||||
"AdditionalImagesCount",
|
"AdditionalImagesCount",
|
||||||
"Status",
|
"Status",
|
||||||
"Details"
|
"Details"
|
||||||
@ -107,7 +106,6 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
"ArticleJsonPath": "",
|
"ArticleJsonPath": "",
|
||||||
"OutputTxtPath": "",
|
"OutputTxtPath": "",
|
||||||
"PosterPath": "",
|
"PosterPath": "",
|
||||||
"CollagePath": "",
|
|
||||||
"AdditionalImagesCount": 0,
|
"AdditionalImagesCount": 0,
|
||||||
"Status": "Processing",
|
"Status": "Processing",
|
||||||
"Details": ""
|
"Details": ""
|
||||||
@ -140,11 +138,6 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
with open(txt_path, 'w', encoding='utf-8') as f_txt:
|
with open(txt_path, 'w', encoding='utf-8') as f_txt:
|
||||||
f_txt.write(txt_content)
|
f_txt.write(txt_content)
|
||||||
print(f" - 成功写入文本文件: {txt_path}")
|
print(f" - 成功写入文本文件: {txt_path}")
|
||||||
|
|
||||||
# 同时保存原始JSON
|
|
||||||
json_output_path = os.path.join(output_entry_path, "article.json")
|
|
||||||
shutil.copy2(json_path, json_output_path)
|
|
||||||
print(f" - 复制原始JSON文件: {json_output_path}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
record["Status"] = "Partial"
|
record["Status"] = "Partial"
|
||||||
record["Details"] += f"写入文本文件失败: {e}; "
|
record["Details"] += f"写入文本文件失败: {e}; "
|
||||||
@ -164,13 +157,6 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
try:
|
try:
|
||||||
shutil.copy2(poster_jpg_path, output_poster_path)
|
shutil.copy2(poster_jpg_path, output_poster_path)
|
||||||
print(f" - 成功复制海报图片: {output_poster_path}")
|
print(f" - 成功复制海报图片: {output_poster_path}")
|
||||||
|
|
||||||
# 复制元数据
|
|
||||||
poster_metadata_path = os.path.join(poster_dir, "poster_metadata.json")
|
|
||||||
if os.path.exists(poster_metadata_path):
|
|
||||||
output_poster_metadata = os.path.join(output_entry_path, "poster_metadata.json")
|
|
||||||
shutil.copy2(poster_metadata_path, output_poster_metadata)
|
|
||||||
print(f" - 复制海报元数据: {output_poster_metadata}")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
record["Status"] = "Partial"
|
record["Status"] = "Partial"
|
||||||
record["Details"] += f"复制海报图片失败: {e}; "
|
record["Details"] += f"复制海报图片失败: {e}; "
|
||||||
@ -180,33 +166,7 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
record["Details"] += "海报图片不存在; "
|
record["Details"] += "海报图片不存在; "
|
||||||
print(f" - 警告: {record['Details']}")
|
print(f" - 警告: {record['Details']}")
|
||||||
|
|
||||||
# 3. 处理拼贴图
|
# 3. 处理额外图片
|
||||||
collage_dir = os.path.join(entry_path, "collage_img")
|
|
||||||
collage_path = os.path.join(collage_dir, "collage.png")
|
|
||||||
output_collage_path = os.path.join(output_entry_path, "collage.png")
|
|
||||||
record["CollagePath"] = output_collage_path
|
|
||||||
|
|
||||||
if os.path.exists(collage_path):
|
|
||||||
try:
|
|
||||||
shutil.copy2(collage_path, output_collage_path)
|
|
||||||
print(f" - 成功复制拼贴图: {output_collage_path}")
|
|
||||||
|
|
||||||
# 复制元数据
|
|
||||||
collage_metadata_path = os.path.join(collage_dir, "collage_metadata.json")
|
|
||||||
if os.path.exists(collage_metadata_path):
|
|
||||||
output_collage_metadata = os.path.join(output_entry_path, "collage_metadata.json")
|
|
||||||
shutil.copy2(collage_metadata_path, output_collage_metadata)
|
|
||||||
print(f" - 复制拼贴图元数据: {output_collage_metadata}")
|
|
||||||
except Exception as e:
|
|
||||||
record["Status"] = "Partial"
|
|
||||||
record["Details"] += f"复制拼贴图失败: {e}; "
|
|
||||||
print(f" - 错误: {record['Details']}")
|
|
||||||
else:
|
|
||||||
record["Status"] = "Partial"
|
|
||||||
record["Details"] += "拼贴图不存在; "
|
|
||||||
print(f" - 警告: {record['Details']}")
|
|
||||||
|
|
||||||
# 4. 处理额外图片
|
|
||||||
image_dir = os.path.join(entry_path, "image")
|
image_dir = os.path.join(entry_path, "image")
|
||||||
output_image_dir = os.path.join(output_entry_path, "additional_images")
|
output_image_dir = os.path.join(output_entry_path, "additional_images")
|
||||||
|
|
||||||
@ -224,13 +184,6 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
shutil.copy2(source_file, dest_file)
|
shutil.copy2(source_file, dest_file)
|
||||||
image_count += 1
|
image_count += 1
|
||||||
|
|
||||||
# 复制相关元数据
|
|
||||||
metadata_filename = filename.replace(".jpg", "_metadata.json")
|
|
||||||
metadata_path = os.path.join(image_dir, metadata_filename)
|
|
||||||
if os.path.exists(metadata_path):
|
|
||||||
dest_metadata = os.path.join(output_image_dir, metadata_filename)
|
|
||||||
shutil.copy2(metadata_path, dest_metadata)
|
|
||||||
|
|
||||||
record["AdditionalImagesCount"] = image_count
|
record["AdditionalImagesCount"] = image_count
|
||||||
print(f" - 复制了 {image_count} 张额外图片到: {output_image_dir}")
|
print(f" - 复制了 {image_count} 张额外图片到: {output_image_dir}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -264,22 +217,24 @@ def process_result_directory(source_dir, output_dir, run_id=None):
|
|||||||
print(f"结果保存在: {output_dir}")
|
print(f"结果保存在: {output_dir}")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="从TravelContentCreator结果目录提取内容并渲染到指定目录")
|
# parser = argparse.ArgumentParser(description="从TravelContentCreator结果目录提取内容并渲染到指定目录")
|
||||||
parser.add_argument("--source", type=str, required=True, help="源目录路径")
|
# parser.add_argument("--source", type=str, required=True, help="源目录路径")
|
||||||
parser.add_argument("--output", type=str, required=True, help="输出目录路径")
|
# parser.add_argument("--output", type=str, required=True, help="输出目录路径")
|
||||||
parser.add_argument("--run-id", type=str, help="自定义运行ID")
|
# parser.add_argument("--run-id", type=str, help="自定义运行ID")
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
|
# args = parser.parse_args()
|
||||||
|
source = ""
|
||||||
|
output = ""
|
||||||
|
run_id = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
print("-" * 60)
|
print("-" * 60)
|
||||||
print(f"开始提取和渲染流程")
|
print(f"开始提取和渲染流程")
|
||||||
print(f"源目录: {args.source}")
|
print(f"源目录: {source}")
|
||||||
print(f"输出目录: {args.output}")
|
print(f"输出目录: {output}")
|
||||||
if args.run_id:
|
if run_id:
|
||||||
print(f"运行ID: {args.run_id}")
|
print(f"运行ID: {run_id}")
|
||||||
print("-" * 60)
|
print("-" * 60)
|
||||||
|
|
||||||
process_result_directory(args.source, args.output, args.run_id)
|
process_result_directory(source, output, run_id)
|
||||||
|
|
||||||
print("\n脚本执行完毕.")
|
print("\n脚本执行完毕.")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user