(self, source_id: str, source: dict)
| 1856 | return any(mc in category for mc in self._MEDICAL_DEVICE_CATEGORIES) |
| 1857 | |
| 1858 | def check(self, source_id: str, source: dict) -> Optional[dict]: |
| 1859 | prev = self.state.get(source_id, {}) |
| 1860 | prev_nids = set(str(n) for n in prev.get("seen_nids", [])) |
| 1861 | |
| 1862 | try: |
| 1863 | resp = self.session.get(self.DATA_URL, timeout=60) |
| 1864 | resp.raise_for_status() |
| 1865 | all_records = resp.json() |
| 1866 | except Exception as e: |
| 1867 | print(f" ERROR Canada Open Data: {e}") |
| 1868 | return None |
| 1869 | |
| 1870 | cutoff = (datetime.now() - timedelta(days=90)).strftime("%Y-%m-%d") |
| 1871 | md_records = [] |
| 1872 | for r in all_records: |
| 1873 | if not self._is_medical_device(r): |
| 1874 | continue |
| 1875 | updated = r.get("Last updated", "") or "" |
| 1876 | if updated >= cutoff: |
| 1877 | md_records.append(r) |
| 1878 | |
| 1879 | print(f" INFO: {len(md_records)} medical device records in last 90 days (from {len(all_records)} total)") |
| 1880 | |
| 1881 | new_items = [] |
| 1882 | all_nids = list(prev_nids) |
| 1883 | |
| 1884 | for r in md_records: |
| 1885 | nid = str(r.get("NID", "")) |
| 1886 | if not nid or nid in prev_nids: |
| 1887 | continue |
| 1888 | all_nids.append(nid) |
| 1889 | title = r.get("Title", "Untitled") |
| 1890 | url = r.get("URL", "") |
| 1891 | if url and not url.startswith("http"): |
| 1892 | url = "https://recalls-rappels.canada.ca" + url |
| 1893 | new_items.append({ |
| 1894 | "title": title, |
| 1895 | "link": url, |
| 1896 | "pub_date": (r.get("Last updated", "") or "")[:10], |
| 1897 | "description": (r.get("Issue", "") or "")[:400], |
| 1898 | "recall_class": r.get("Recall class", ""), |
| 1899 | "category": r.get("Category", ""), |
| 1900 | }) |
| 1901 | |
| 1902 | self.state[source_id] = { |
| 1903 | "url": self.DATA_URL, |
| 1904 | "last_checked": datetime.now().isoformat(), |
| 1905 | "seen_nids": all_nids[-1000:], |
| 1906 | } |
| 1907 | |
| 1908 | if new_items and (prev_nids or self.seed_mode): |
| 1909 | if self.seed_mode and not prev_nids: |
| 1910 | new_items = new_items[:10] |
| 1911 | print(f" INFO: Seed mode -- returning top {len(new_items)} medical device entries") |
| 1912 | result = _make_update( |
| 1913 | source_id, source, "canada_recalls", |
| 1914 | f"{len(new_items)} new Canada medical device recall(s)/alert(s)" |
| 1915 | ) |
nothing calls this directly
no test coverage detected