Remove entities from must-read list
(profile, entity_type, entities)
| 205 | |
| 206 | |
| 207 | def remove_must_read(profile, entity_type, entities): |
| 208 | """Remove entities from must-read list""" |
| 209 | must_read = profile.get('must_read', {}) |
| 210 | current_list = must_read.get(entity_type, []) |
| 211 | removed, not_found = [], [] |
| 212 | for entity in entities: |
| 213 | if entity in current_list: |
| 214 | current_list.remove(entity) |
| 215 | removed.append(entity) |
| 216 | else: |
| 217 | not_found.append(entity) |
| 218 | |
| 219 | updated = profile.copy() |
| 220 | updated['must_read'] = must_read |
| 221 | updated['version'] = f"0.{int(profile.get('version', '0.1').split('.')[1]) + 1}" |
| 222 | updated['updated_at'] = datetime.now().isoformat() |
| 223 | |
| 224 | type_labels = {'authors': '作者', 'institutions': '机构', 'keywords': '关键词'} |
| 225 | label = type_labels.get(entity_type, entity_type) |
| 226 | |
| 227 | if removed: |
| 228 | msg = f"[OK] 已删除 {label}:" + ", ".join(removed) |
| 229 | if current_list: |
| 230 | msg += f"\n\n当前必读{label}清单:\n" + "\n".join(f" - {e}" for e in current_list) |
| 231 | else: |
| 232 | msg += f"\n当前必读{label}清单为空" |
| 233 | elif not_found: |
| 234 | msg = f"[提示] {', '.join(not_found)} 不在必读{label}清单中" |
| 235 | else: |
| 236 | msg = "[错误] 未删除任何内容" |
| 237 | return (len(removed) > 0, msg, updated if removed else None) |
| 238 | |
| 239 | |
| 240 | def list_must_read(profile): |