feat: 图片改为参数截图,支持多次解析并记录解析来源历史
This commit is contained in:
106
app.py
106
app.py
@@ -570,10 +570,18 @@ def api_smart_update_model(model_id):
|
||||
updated_fields.append(key)
|
||||
|
||||
model['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
model['raw_text'] = model.get('raw_text', '') + '\n' + text if text else model.get('raw_text', '')
|
||||
if images:
|
||||
existing_images = model.get('images', [])
|
||||
model['images'] = existing_images + images
|
||||
|
||||
# 追加解析来源记录
|
||||
parse_source = {
|
||||
'type': 'smart_update',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else '',
|
||||
'updated_fields': updated_fields
|
||||
}
|
||||
if 'parse_sources' not in model:
|
||||
model['parse_sources'] = []
|
||||
model['parse_sources'].append(parse_source)
|
||||
|
||||
save_data(MODELS_FILE, models)
|
||||
|
||||
@@ -609,10 +617,17 @@ def api_smart_update_gpu(gpu_id):
|
||||
updated_fields.append(key)
|
||||
|
||||
gpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
gpu['raw_text'] = gpu.get('raw_text', '') + '\n' + text if text else gpu.get('raw_text', '')
|
||||
if images:
|
||||
existing_images = gpu.get('images', [])
|
||||
gpu['images'] = existing_images + images
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_update',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else '',
|
||||
'updated_fields': updated_fields
|
||||
}
|
||||
if 'parse_sources' not in gpu:
|
||||
gpu['parse_sources'] = []
|
||||
gpu['parse_sources'].append(parse_source)
|
||||
|
||||
save_data(GPUS_FILE, gpus)
|
||||
|
||||
@@ -648,10 +663,17 @@ def api_smart_update_cpu(cpu_id):
|
||||
updated_fields.append(key)
|
||||
|
||||
cpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
cpu['raw_text'] = cpu.get('raw_text', '') + '\n' + text if text else cpu.get('raw_text', '')
|
||||
if images:
|
||||
existing_images = cpu.get('images', [])
|
||||
cpu['images'] = existing_images + images
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_update',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else '',
|
||||
'updated_fields': updated_fields
|
||||
}
|
||||
if 'parse_sources' not in cpu:
|
||||
cpu['parse_sources'] = []
|
||||
cpu['parse_sources'].append(parse_source)
|
||||
|
||||
save_data(CPUS_FILE, cpus)
|
||||
|
||||
@@ -688,10 +710,17 @@ def api_smart_update_item(category_id, item_id):
|
||||
updated_fields.append(key)
|
||||
|
||||
item['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
item['raw_text'] = item.get('raw_text', '') + '\n' + text if text else item.get('raw_text', '')
|
||||
if images:
|
||||
existing_images = item.get('images', [])
|
||||
item['images'] = existing_images + images
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_update',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else '',
|
||||
'updated_fields': updated_fields
|
||||
}
|
||||
if 'parse_sources' not in item:
|
||||
item['parse_sources'] = []
|
||||
item['parse_sources'].append(parse_source)
|
||||
|
||||
save_data(items_file, items)
|
||||
|
||||
@@ -715,17 +744,25 @@ def api_smart_add_model():
|
||||
results = []
|
||||
models = load_data(MODELS_FILE)
|
||||
|
||||
# 构建解析来源记录
|
||||
parse_source = {
|
||||
'type': 'smart_add',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else '' # 截取前500字符
|
||||
}
|
||||
|
||||
for parsed in parsed_list:
|
||||
# 补充必要字段
|
||||
parsed['id'] = uuid.uuid4().hex[:12]
|
||||
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
parsed['visible'] = True
|
||||
parsed['raw_text'] = text
|
||||
parsed['images'] = images
|
||||
parsed['subcategory_id'] = subcategory_id # 保存子类别
|
||||
parsed['publish_date'] = parsed.get('publish_date', '')
|
||||
parsed['views'] = 0
|
||||
parsed['is_pinned'] = False
|
||||
parsed['product_images'] = [] # 产品展示图(不同于参数截图)
|
||||
parsed['parse_sources'] = [parse_source] # 解析来源历史
|
||||
|
||||
models.append(parsed)
|
||||
results.append(parsed)
|
||||
@@ -750,16 +787,23 @@ def api_smart_add_gpu():
|
||||
results = []
|
||||
gpus = load_data(GPUS_FILE)
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_add',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else ''
|
||||
}
|
||||
|
||||
for parsed in parsed_list:
|
||||
parsed['id'] = uuid.uuid4().hex[:12]
|
||||
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
parsed['visible'] = True
|
||||
parsed['raw_text'] = text
|
||||
parsed['images'] = images
|
||||
parsed['subcategory_id'] = subcategory_id
|
||||
parsed['publish_date'] = parsed.get('publish_date', '')
|
||||
parsed['views'] = 0
|
||||
parsed['is_pinned'] = False
|
||||
parsed['product_images'] = []
|
||||
parsed['parse_sources'] = [parse_source]
|
||||
|
||||
gpus.append(parsed)
|
||||
results.append(parsed)
|
||||
@@ -784,16 +828,23 @@ def api_smart_add_cpu():
|
||||
results = []
|
||||
cpus = load_data(CPUS_FILE)
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_add',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else ''
|
||||
}
|
||||
|
||||
for parsed in parsed_list:
|
||||
parsed['id'] = uuid.uuid4().hex[:12]
|
||||
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
parsed['visible'] = True
|
||||
parsed['raw_text'] = text
|
||||
parsed['images'] = images
|
||||
parsed['subcategory_id'] = subcategory_id
|
||||
parsed['publish_date'] = parsed.get('publish_date', '')
|
||||
parsed['views'] = 0
|
||||
parsed['is_pinned'] = False
|
||||
parsed['product_images'] = []
|
||||
parsed['parse_sources'] = [parse_source]
|
||||
|
||||
cpus.append(parsed)
|
||||
results.append(parsed)
|
||||
@@ -820,17 +871,24 @@ def api_smart_add_item(category_id):
|
||||
items_file = DATA_DIR / f'items_{category_id}.json'
|
||||
items = load_data(items_file)
|
||||
|
||||
parse_source = {
|
||||
'type': 'smart_add',
|
||||
'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'images': images,
|
||||
'text': text[:500] if text else ''
|
||||
}
|
||||
|
||||
for parsed in parsed_list:
|
||||
parsed['id'] = uuid.uuid4().hex[:12]
|
||||
parsed['category_id'] = category_id
|
||||
parsed['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
parsed['visible'] = True
|
||||
parsed['raw_text'] = text
|
||||
parsed['images'] = images
|
||||
parsed['subcategory_id'] = subcategory_id
|
||||
parsed['publish_date'] = parsed.get('publish_date', '')
|
||||
parsed['views'] = 0
|
||||
parsed['is_pinned'] = False
|
||||
parsed['product_images'] = []
|
||||
parsed['parse_sources'] = [parse_source]
|
||||
|
||||
items.append(parsed)
|
||||
results.append(parsed)
|
||||
|
||||
Reference in New Issue
Block a user