INNER CODE UNIT · Python
_celestrak_url
ATTron/astroz · bindings/python/astroz/__init__.py:64
def _celestrak_url(group=None, norad_id=None):
if norad_id is not None:
ids = ",".join(map(str, norad_id)) if isinstance(norad_id, (list, tuple)) else str(norad_id)
query = f"CATNR={ids}"
else:
query = f"GROUP={_CELESTRAK_ALIASES.get(group.lower(), group)}"
return f"https://celestrak.org/NORAD/elements/gp.php?{query}&FORMAT=TLE"
def _load_tle_text(source, norad_id=None):
"""Returns (text, format) where format is "tle" or "json"."""
if norad_id is not None:
return _fetch_url(_celestrak_url(norad_id=norad_id)), "tle"
if source is None:
raise ValueError("Must specify 'source' or 'norad_id'")
if source.startswith(("http://", "https://")):
text = _fetch_url(source)
fmt = "json" if text.lstrip().startswith(("[", "{")) else "tle"