MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / add_must_read

Function add_must_read

scripts/add_must_read.py:162–204  ·  view source on GitHub ↗

Add entities to must-read list

(profile, entity_type, entities)

Source from the content-addressed store, hash-verified

160
161def add_must_read(profile, entity_type, entities):
162 """Add entities to must-read list"""
163 must_read = profile.get('must_read', {})
164 current_list = must_read.get(entity_type, [])
165 added, already_exists, routed_to_interest = [], [], []
166 for entity in entities:
167 if entity_type == "keywords":
168 broad_direction = _resolve_broad_must_read_keyword(entity)
169 if broad_direction:
170 routed_to_interest.append(
171 _route_keyword_to_interest_direction(profile, current_list, entity, broad_direction)
172 )
173 continue
174 if entity in current_list:
175 already_exists.append(entity)
176 else:
177 added.append(entity)
178 current_list.append(entity)
179
180 must_read[entity_type] = current_list
181 updated = profile.copy()
182 updated['must_read'] = must_read
183 updated['version'] = f"0.{int(profile.get('version', '0.1').split('.')[1]) + 1}"
184 updated['updated_at'] = datetime.now().isoformat()
185
186 type_labels = {'authors': '作者', 'institutions': '机构', 'keywords': '关键词'}
187 label = type_labels.get(entity_type, entity_type)
188
189 if added or routed_to_interest:
190 msg = f"[OK] 已添加 {label}:" + ", ".join(added)
191 if not added:
192 msg = "[OK] 已更新兴趣方向"
193 if routed_to_interest:
194 msg += "\n[提示] 以下宽泛关键词已转为软兴趣方向,不进入硬必读:"
195 msg += "\n" + "\n".join(f" - {item}" for item in routed_to_interest)
196 if already_exists:
197 msg += "\n[提示] 已存在:" + ", ".join(already_exists)
198 msg += f"\n\n当前必读{label}清单:\n" + "\n".join(f" - {e}" for e in current_list)
199 elif already_exists:
200 msg = f"[提示] {', '.join(already_exists)} 已在必读{label}清单中"
201 else:
202 msg = "[错误] 未添加任何内容"
203 return (bool(added or routed_to_interest), msg, updated if (added or routed_to_interest) else None)
204
205
206def remove_must_read(profile, entity_type, entities):
207 """Remove entities from must-read list"""

Callers 1

mainFunction · 0.70

Calls 4

getMethod · 0.80
nowMethod · 0.80

Tested by

no test coverage detected