修改了海报文案默认配置, 目前默认全部为空

This commit is contained in:
jinye_huang 2025-04-27 10:05:40 +08:00
parent a00788964d
commit ff3159f454
2 changed files with 23 additions and 23 deletions

View File

@ -296,8 +296,8 @@ class ContentGenerator:
for i in range(poster_num):
default_configs.append({
"index": i + 1,
"main_title": f"景点风光 {i+1}",
"texts": ["自然美景", "人文体验"]
"main_title": f" ",
"texts": [" ", " "]
})
return json.dumps(default_configs, ensure_ascii=False)
@ -337,7 +337,7 @@ class ContentGenerator:
except Exception as e:
self.logger.error(f"保存结果到文件时出错: {e}")
# 尝试创建一个简单的备用配置
fallback_data = [{"main_title": "景点风光", "texts": ["自然美景", "人文体验"], "index": 1}]
fallback_data = [{"main_title": " ", "texts": [" ", " "], "index": 1}]
# 保存备用数据
result_path = os.path.join(output_dir, f"{date_time}_fallback.json")
@ -369,23 +369,23 @@ class ContentGenerator:
# 确保必需字段存在
fixed_item = {
"index": item.get("index", i + 1),
"main_title": item.get("main_title", f"景点风光 {i+1}"),
"texts": item.get("texts", ["自然美景", "人文体验"])
"main_title": item.get("main_title", f""),
"texts": item.get("texts", [" ", " "])
}
# 确保texts是列表格式
if not isinstance(fixed_item["texts"], list):
if isinstance(fixed_item["texts"], str):
fixed_item["texts"] = [fixed_item["texts"], "美景体验"]
fixed_item["texts"] = [fixed_item["texts"], " "]
else:
fixed_item["texts"] = ["自然美景", "人文体验"]
fixed_item["texts"] = [" ", " "]
# 限制texts最多包含两个元素
if len(fixed_item["texts"]) > 2:
fixed_item["texts"] = fixed_item["texts"][:2]
elif len(fixed_item["texts"]) < 2:
while len(fixed_item["texts"]) < 2:
fixed_item["texts"].append("美景体验")
fixed_item["texts"].append(" ")
fixed_data.append(fixed_item)
@ -394,39 +394,39 @@ class ContentGenerator:
self.logger.warning(f"配置项 {i+1} 是字符串格式,将转换为标准格式")
fixed_item = {
"index": i + 1,
"main_title": f"景点风光 {i+1}",
"texts": [item, "美景体验"]
"main_title": f"",
"texts": [item, " "]
}
fixed_data.append(fixed_item)
else:
self.logger.warning(f"配置项 {i+1} 格式不支持: {type(item)},将使用默认值")
fixed_data.append({
"index": i + 1,
"main_title": f"景点风光 {i+1}",
"texts": ["自然美景", "人文体验"]
"main_title": f"",
"texts": [" ", " "]
})
# 如果数据是字典
elif isinstance(data, dict):
fixed_item = {
"index": data.get("index", 1),
"main_title": data.get("main_title", "景点风光"),
"texts": data.get("texts", ["自然美景", "人文体验"])
"main_title": data.get("main_title", ""),
"texts": data.get("texts", [" ", " "])
}
# 确保texts是列表格式
if not isinstance(fixed_item["texts"], list):
if isinstance(fixed_item["texts"], str):
fixed_item["texts"] = [fixed_item["texts"], "美景体验"]
fixed_item["texts"] = [fixed_item["texts"], " "]
else:
fixed_item["texts"] = ["自然美景", "人文体验"]
fixed_item["texts"] = [" ", " "]
# 限制texts最多包含两个元素
if len(fixed_item["texts"]) > 2:
fixed_item["texts"] = fixed_item["texts"][:2]
elif len(fixed_item["texts"]) < 2:
while len(fixed_item["texts"]) < 2:
fixed_item["texts"].append("美景体验")
fixed_item["texts"].append(" ")
fixed_data.append(fixed_item)
@ -435,16 +435,16 @@ class ContentGenerator:
self.logger.warning(f"数据格式不支持: {type(data)},将使用默认值")
fixed_data.append({
"index": 1,
"main_title": "景点风光",
"texts": ["自然美景", "人文体验"]
"main_title": " ",
"texts": [" ", " "]
})
# 确保至少有一个配置项
if not fixed_data:
fixed_data.append({
"index": 1,
"main_title": "景点风光",
"texts": ["自然美景", "人文体验"]
"main_title": " ",
"texts": [" ", " "]
})
return fixed_data
@ -506,8 +506,8 @@ class ContentGenerator:
for i in range(poster_num):
default_configs.append({
"index": i + 1,
"main_title": f"景点风光 {i+1}",
"texts": ["自然美景", "人文体验"]
"main_title": f" ",
"texts": [" ", " "]
})
return default_configs