按 NORAD 卫星编号(CATNR)拉取 TLE 条目。 参数 ---- catnr : int NORAD 卫星目录编号(如 25544 为 ISS)。 force_refresh : bool 强制刷新,忽略缓存。 返回 ---- list of TleEntry 通常包含 0 或 1 条记录。
(catnr: int, force_refresh: bool = False)
| 271 | |
| 272 | |
| 273 | def fetch_by_catnr(catnr: int, force_refresh: bool = False) -> List[TleEntry]: |
| 274 | """按 NORAD 卫星编号(CATNR)拉取 TLE 条目。 |
| 275 | |
| 276 | 参数 |
| 277 | ---- |
| 278 | catnr : int |
| 279 | NORAD 卫星目录编号(如 25544 为 ISS)。 |
| 280 | force_refresh : bool |
| 281 | 强制刷新,忽略缓存。 |
| 282 | |
| 283 | 返回 |
| 284 | ---- |
| 285 | list of TleEntry |
| 286 | 通常包含 0 或 1 条记录。 |
| 287 | """ |
| 288 | group_key = f"catnr_{catnr}" |
| 289 | |
| 290 | if not force_refresh and _cache_is_fresh(group_key): |
| 291 | cached = _read_cache(group_key) |
| 292 | if cached: |
| 293 | return _parse_tle_text(cached) |
| 294 | |
| 295 | url = f"https://celestrak.org/SOCRATES/query.php?FORMAT=TLE&CATNR={catnr}" |
| 296 | try: |
| 297 | raw_text = _http_get(url, timeout=_FETCH_TIMEOUT) |
| 298 | if raw_text and raw_text.strip(): |
| 299 | _write_cache(group_key, raw_text) |
| 300 | return _parse_tle_text(raw_text) |
| 301 | except Exception as exc: |
| 302 | logger.warning("Celestrak CATNR 拉取失败: catnr=%d, error=%s", catnr, exc) |
| 303 | |
| 304 | cached = _read_cache(group_key) |
| 305 | if cached: |
| 306 | return _parse_tle_text(cached) |
| 307 | return [] |
| 308 | |
| 309 | |
| 310 | def _http_get(url: str, timeout: int = 15) -> str: |
no test coverage detected