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

Method check

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

Source from the content-addressed store, hash-verified

1379 self.state = state
1380
1381 def check(self, source_id: str, source: dict) -> Optional[dict]:
1382 prev = self.state.get(source_id, {})
1383 seen_ids = set(prev.get("seen_res_numbers", []))
1384
1385 lookback = (datetime.now() - timedelta(days=30)).strftime("%Y%m%d")
1386 today = datetime.now().strftime("%Y%m%d")
1387
1388 search_q = f'event_date_initiated:[{lookback} TO {today}]'
1389 url = (
1390 f"{self.RECALL_URL}"
1391 f"?search={requests.utils.quote(search_q)}"
1392 f"&sort=event_date_initiated:desc&limit=30"
1393 )
1394 if self.api_key:
1395 url += f"&api_key={self.api_key}"
1396
1397 try:
1398 resp = requests.get(url, timeout=20)
1399 if resp.status_code == 404:
1400 self.state[source_id] = {
1401 "url": source["url"],
1402 "last_checked": datetime.now().isoformat(),
1403 "seen_res_numbers": list(seen_ids),
1404 }
1405 return None
1406 resp.raise_for_status()
1407 results = resp.json().get("results", [])
1408 except Exception as e:
1409 print(f" ERROR OpenFDA Recall: {e}")
1410 return None
1411
1412 new_items = []
1413 all_ids = list(seen_ids)
1414
1415 for r in results:
1416 res_num = r.get("product_res_number") or r.get("res_event_number", "")
1417 if not res_num or res_num in seen_ids:
1418 continue
1419 all_ids.append(res_num)
1420
1421 firm = r.get("recalling_firm", "Unknown")
1422 product = (r.get("product_description") or "")[:120]
1423 reason = r.get("reason_for_recall", "")
1424 cfres_id = r.get("cfres_id", "")
1425 init_date = r.get("event_date_initiated", "")
1426
1427 title = f"Device Recall: {firm} - {product}"
1428 description = f"Recall {res_num}: {reason[:250]}"
1429 link = (
1430 f"https://www.accessdata.fda.gov/scripts/cdrh/cfdocs/cfRes/res.cfm"
1431 f"?id={cfres_id}"
1432 ) if cfres_id else source["url"]
1433
1434 new_items.append({
1435 "title": title,
1436 "link": link,
1437 "pub_date": self._format_date(init_date),
1438 "description": description,

Callers

nothing calls this directly

Calls 3

_format_dateMethod · 0.95
getMethod · 0.80
_make_updateFunction · 0.70

Tested by

no test coverage detected