MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / check

Method check

scripts/fetch_updates.py:1265–1315  ·  view source on GitHub ↗
(self, source_id: str, source: dict)

Source from the content-addressed store, hash-verified

1263 self.state = state
1264
1265 def check(self, source_id: str, source: dict) -> Optional[dict]:
1266 prev = self.state.get(source_id, {})
1267 prev_titles = set(prev.get("seen_titles", []))
1268
1269 try:
1270 resp = self.session.get(self.URL, timeout=30)
1271 resp.raise_for_status()
1272 except Exception as e:
1273 print(f" ERROR fetching EC Latest Updates: {e}")
1274 return None
1275
1276 entries = self._parse_entries(resp.text)
1277 if not entries:
1278 print(f" WARNING: No entries parsed from EC Latest Updates page")
1279 return None
1280
1281 print(f" INFO: Parsed {len(entries)} entries from EC Latest Updates page")
1282
1283 new_items = []
1284 all_titles = list(prev_titles)
1285
1286 for entry in entries:
1287 title = entry.get("title", "")
1288 if not title or title in prev_titles:
1289 continue
1290 all_titles.append(title)
1291 new_items.append({
1292 "title": title,
1293 "link": entry.get("link", ""),
1294 "pub_date": entry.get("date", ""),
1295 "description": entry.get("type", ""),
1296 })
1297
1298 self.state[source_id] = {
1299 "url": source["url"],
1300 "last_checked": datetime.now().isoformat(),
1301 "seen_titles": all_titles[-200:],
1302 "total_entries": len(entries),
1303 }
1304
1305 if new_items and prev_titles:
1306 result = _make_update(
1307 source_id, source, "ec_latest_updates",
1308 f"{len(new_items)} new EC Medical Devices update(s) detected"
1309 )
1310 result["new_items"] = new_items
1311 return result
1312 elif not prev_titles:
1313 print(f" INFO: Baseline established ({len(entries)} entries indexed)")
1314
1315 return None
1316
1317 def _parse_entries(self, html: str) -> list[dict]:
1318 """Parse article blocks from EC Latest Updates page."""

Callers

nothing calls this directly

Calls 3

_parse_entriesMethod · 0.95
getMethod · 0.80
_make_updateFunction · 0.70

Tested by

no test coverage detected