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

Method check

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

Source from the content-addressed store, hash-verified

748 return []
749
750 def check(self, source_id: str, source: dict) -> Optional[dict]:
751 query = source.get("google_query")
752 if not query or not self.available:
753 if not self.available:
754 print(f" SKIP (Google CSE not configured)")
755 return None
756 title_filter = source.get("title_filter")
757 prev = self.state.get(source_id, {})
758 prev_titles = set(prev.get("seen_titles", []))
759 date_restrict = source.get("date_restrict", "")
760 items = self.search(query, date_restrict=date_restrict)
761 new_items = []
762 filtered_count = 0
763 all_titles = list(prev_titles)
764 for item in items:
765 title = item.get("title", "")
766 if title_filter and not re.search(title_filter, title, re.IGNORECASE):
767 filtered_count += 1
768 continue
769 if title not in prev_titles:
770 new_items.append({"title": title, "link": item.get("link", ""),
771 "snippet": item.get("snippet", "")[:200]})
772 all_titles.append(title)
773 if filtered_count:
774 print(f" INFO: {filtered_count} results filtered by title_filter")
775 self.state[source_id] = {"url": source["url"],
776 "last_checked": datetime.now().isoformat(),
777 "seen_titles": all_titles[-100:]}
778 if new_items and (prev_titles or self.seed_mode):
779 if self.seed_mode and not prev_titles:
780 new_items = new_items[:10]
781 print(f" INFO: Seed mode -- returning top {len(new_items)} results as initial news")
782 result = _make_update(source_id, source, "google_search",
783 f"{len(new_items)} new result(s) via Google Search")
784 result["new_items"] = new_items
785 result["query"] = query
786 return result
787 elif not prev_titles:
788 print(f" INFO: Baseline established ({len(items)} results indexed)")
789 return None
790
791
792# ---------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 3

searchMethod · 0.95
getMethod · 0.80
_make_updateFunction · 0.70

Tested by

no test coverage detected