(self, source_id: str, source: dict)
| 1941 | self.seed_mode = seed_mode |
| 1942 | |
| 1943 | def check(self, source_id: str, source: dict) -> Optional[dict]: |
| 1944 | url = source["url"] |
| 1945 | prev = self.state.get(source_id, {}) |
| 1946 | prev_ids = set(prev.get("seen_ids", [])) |
| 1947 | title_filter = source.get("title_filter") |
| 1948 | title_exclude = source.get("title_exclude") |
| 1949 | |
| 1950 | try: |
| 1951 | resp = self.session.get(url, timeout=30) |
| 1952 | resp.raise_for_status() |
| 1953 | except Exception as e: |
| 1954 | print(f" ERROR PMDA What's New: {e}") |
| 1955 | return None |
| 1956 | |
| 1957 | entries = self._parse_whatsnew(resp.text) |
| 1958 | if not entries: |
| 1959 | print(" WARNING: No entries from PMDA What's New page") |
| 1960 | return None |
| 1961 | |
| 1962 | print(f" INFO: Parsed {len(entries)} entries from PMDA What's New") |
| 1963 | |
| 1964 | new_items = [] |
| 1965 | all_ids = list(prev_ids) |
| 1966 | |
| 1967 | for entry in entries: |
| 1968 | eid = entry.get("link") or entry.get("title", "") |
| 1969 | if not eid or eid in prev_ids: |
| 1970 | continue |
| 1971 | title = entry.get("title", "") |
| 1972 | if title_filter and not re.search(title_filter, title, re.IGNORECASE): |
| 1973 | all_ids.append(eid) |
| 1974 | continue |
| 1975 | if title_exclude and re.search(title_exclude, title, re.IGNORECASE): |
| 1976 | all_ids.append(eid) |
| 1977 | continue |
| 1978 | all_ids.append(eid) |
| 1979 | new_items.append(entry) |
| 1980 | |
| 1981 | self.state[source_id] = { |
| 1982 | "url": url, |
| 1983 | "last_checked": datetime.now().isoformat(), |
| 1984 | "seen_ids": all_ids[-500:], |
| 1985 | } |
| 1986 | |
| 1987 | if new_items and (prev_ids or self.seed_mode): |
| 1988 | if self.seed_mode and not prev_ids: |
| 1989 | new_items = new_items[:10] |
| 1990 | print(f" INFO: Seed mode -- returning top {len(new_items)} PMDA What's New entries") |
| 1991 | result = _make_update( |
| 1992 | source_id, source, "pmda_whatsnew", |
| 1993 | f"{len(new_items)} new PMDA device update(s) detected" |
| 1994 | ) |
| 1995 | result["new_items"] = new_items |
| 1996 | return result |
| 1997 | elif not prev_ids: |
| 1998 | print(f" INFO: Baseline established ({len(entries)} PMDA What's New entries)") |
| 1999 | |
| 2000 | return None |
nothing calls this directly
no test coverage detected