更新今日的数据刷新

This commit is contained in:
2025-12-01 20:41:47 +08:00
parent ff7e114324
commit 9026aa8f4b
12 changed files with 20692 additions and 25 deletions

View File

@@ -101,19 +101,18 @@ class IntegratedProductSystem:
)
''')
# 创建分析结果表来自product_ai_analysis.py
# 移除了product_intro字段避免与ai_response内容重复
# 创建分析结果表
# 根据最新数据库结构更新
cursor.execute('''
CREATE TABLE IF NOT EXISTS product_analysis (
id INTEGER PRIMARY KEY AUTOINCREMENT,
original_id INTEGER,
original_name TEXT,
product_name TEXT,
product_intro TEXT,
development_difficulty TEXT,
difficulty_score INTEGER,
ai_response TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (original_id) REFERENCES products (id)
difficulty_score INTEGER,
product_link TEXT
)
''')
@@ -328,17 +327,16 @@ class IntegratedProductSystem:
# 使用/分割响应内容
parts = response.split('/')
product_name = ""
product_intro = ""
difficulty = ""
difficulty_score = None
if len(parts) >= 3:
product_name = parts[0].strip()
# 不再使用product_name,直接从原始名称中获取
product_intro = parts[1].strip()
difficulty = parts[2].strip()
logger.info(f"解析结果: 名称='{product_name}', 简介='{product_intro[:30]}...', 难度='{difficulty}'")
logger.info(f"解析结果: 简介='{product_intro[:30]}...', 难度='{difficulty}'")
# 从难度描述中提取分数
import re
@@ -370,11 +368,11 @@ class IntegratedProductSystem:
difficulty = response
difficulty_score = 50 # 默认中等难度
return product_name, product_intro, difficulty, difficulty_score
return product_intro, difficulty, difficulty_score
except Exception as e:
logger.error(f"解析AI响应失败: {e}")
return "", response, "", 50
return "", response, 50
def check_product_exists_in_analysis(self, conn: sqlite3.Connection, original_name: str) -> bool:
"""检查产品是否已存在于分析结果表中"""
@@ -398,9 +396,10 @@ class IntegratedProductSystem:
return False
def save_analysis_result(self, conn: sqlite3.Connection,
original_id: int, original_name: str,
product_name: str, difficulty: str, ai_response: str, difficulty_score: int = None):
"""保存分析结果到数据库,包括难度分数"""
original_name: str, difficulty: str,
ai_response: str, difficulty_score: int = None,
product_link: str = None):
"""保存分析结果到数据库,包括难度分数和产品链接"""
try:
cursor = conn.cursor()
@@ -410,12 +409,12 @@ class IntegratedProductSystem:
cursor.execute("""
INSERT INTO product_analysis
(original_id, original_name, product_name, development_difficulty, difficulty_score, ai_response)
VALUES (?, ?, ?, ?, ?, ?)
""", (original_id, original_name, product_name, difficulty, difficulty_score, ai_response))
(original_name, development_difficulty, difficulty_score, ai_response, product_link)
VALUES (?, ?, ?, ?, ?)
""", (original_name, difficulty, difficulty_score, ai_response, product_link))
conn.commit()
logger.success(f"保存分析结果成功: {product_name}, 难度分数: {difficulty_score}")
logger.success(f"保存分析结果成功: {original_name}, 难度分数: {difficulty_score}")
except Exception as e:
logger.error(f"保存分析结果失败: {e}")
@@ -471,11 +470,10 @@ class IntegratedProductSystem:
logger.info(f"API调用成功正在处理数据...")
# 解析响应
product_name, product_intro, difficulty, difficulty_score = self.parse_ai_response(ai_response)
product_intro, difficulty, difficulty_score = self.parse_ai_response(ai_response)
# 保存结果不再保存product_intro避免与ai_response重复
self.save_analysis_result(conn, original_id, name,
product_name, difficulty, ai_response, difficulty_score)
self.save_analysis_result(conn, name, difficulty, ai_response, difficulty_score)
success_count += 1
# 显示完成状态
@@ -597,9 +595,8 @@ class IntegratedProductSystem:
# 查询缺失难度分数的产品
cursor.execute("""
SELECT pa.id, p.name, p.introduction, pa.ai_response
SELECT pa.id, pa.original_name, pa.product_intro, pa.ai_response
FROM product_analysis pa
JOIN products p ON pa.original_id = p.id
WHERE pa.difficulty_score IS NULL OR pa.difficulty_score = ''
""")