移除必读项 Args: profile: 用户画像 item_type: 类型 value: 值 Returns: 结果字典
(profile: Dict, item_type: str, value: str)
| 317 | |
| 318 | |
| 319 | def remove_must_read(profile: Dict, item_type: str, value: str) -> Dict[str, Any]: |
| 320 | """ |
| 321 | 移除必读项 |
| 322 | |
| 323 | Args: |
| 324 | profile: 用户画像 |
| 325 | item_type: 类型 |
| 326 | value: 值 |
| 327 | |
| 328 | Returns: |
| 329 | 结果字典 |
| 330 | """ |
| 331 | must_read = profile.get("must_read", {"authors": [], "institutions": [], "keywords": []}) |
| 332 | |
| 333 | key = f"{item_type}s" |
| 334 | current_list = must_read.get(key, []) |
| 335 | item_label = ITEM_TYPE_LABELS.get(item_type, item_type) |
| 336 | cleaned_value = clean_must_read_value(value) |
| 337 | normalized_value = normalize_must_read_value(cleaned_value) |
| 338 | matched_value = next( |
| 339 | (item for item in current_list if normalize_must_read_value(str(item)) == normalized_value), |
| 340 | None, |
| 341 | ) |
| 342 | |
| 343 | if matched_value is None: |
| 344 | return {"success": False, "message": f"{cleaned_value} 不在必读清单中"} |
| 345 | |
| 346 | current_list.remove(matched_value) |
| 347 | must_read[key] = current_list |
| 348 | profile["must_read"] = must_read |
| 349 | profile["updated_at"] = datetime.now().isoformat() |
| 350 | |
| 351 | return {"success": True, "message": f"已从必读{item_label}清单中移除 {matched_value}"} |
| 352 | |
| 353 | |
| 354 | def format_must_read_list(profile: Dict) -> str: |
no test coverage detected