MCPcopy Create free account
hub / github.com/Tong89/smartNode / fetch_by_catnr

Function fetch_by_catnr

backend/physics/tle_source.py:273–307  ·  view source on GitHub ↗

按 NORAD 卫星编号(CATNR)拉取 TLE 条目。 参数 ---- catnr : int NORAD 卫星目录编号(如 25544 为 ISS)。 force_refresh : bool 强制刷新,忽略缓存。 返回 ---- list of TleEntry 通常包含 0 或 1 条记录。

(catnr: int, force_refresh: bool = False)

Source from the content-addressed store, hash-verified

271
272
273def 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
310def _http_get(url: str, timeout: int = 15) -> str:

Callers 1

tle_importFunction · 0.90

Calls 5

_cache_is_freshFunction · 0.85
_read_cacheFunction · 0.85
_parse_tle_textFunction · 0.85
_http_getFunction · 0.85
_write_cacheFunction · 0.85

Tested by

no test coverage detected