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

Function tle_import

backend/api.py:1168–1227  ·  view source on GitHub ↗

从 Celestrak 导入指定分组或编号的 TLE 星历并缓存到本地。 请求体(JSON):: { "group": "starlink", # 星座分组名,与 catnr 二选一 "catnr": 25544, # NORAD 卫星编号,与 group 二选一 "force_refresh": false, # 是否强制刷新(可选,默认 false) "inject": false # 是否将 TLE 注入仿真引擎

()

Source from the content-addressed store, hash-verified

1166@require_role('admin')
1167@rate_limit(5, 60)
1168def tle_import():
1169 """从 Celestrak 导入指定分组或编号的 TLE 星历并缓存到本地。
1170
1171 请求体(JSON)::
1172
1173 {
1174 "group": "starlink", # 星座分组名,与 catnr 二选一
1175 "catnr": 25544, # NORAD 卫星编号,与 group 二选一
1176 "force_refresh": false, # 是否强制刷新(可选,默认 false)
1177 "inject": false # 是否将 TLE 注入仿真引擎星座(可选,默认 false)
1178 }
1179
1180 响应示例::
1181
1182 {"code": 0, "data": {
1183 "group": "starlink",
1184 "entry_count": 6000,
1185 "injected": 12,
1186 "first_epoch": "2024-05-01T00:00:00Z",
1187 "cached_at": "2024-05-01T12:00:00Z"
1188 }}
1189 """
1190 body = request.get_json(silent=True) or {}
1191 group = str(body.get("group", "")).strip()
1192 catnr = body.get("catnr")
1193 force_refresh = bool(body.get("force_refresh", False))
1194 do_inject = bool(body.get("inject", False))
1195
1196 if not group and catnr is None:
1197 return error_response("VALIDATION_ERROR", "必须提供 'group'(星座名)或 'catnr'(NORAD 编号)之一")
1198
1199 try:
1200 if catnr is not None:
1201 try:
1202 catnr_int = int(catnr)
1203 except (TypeError, ValueError):
1204 return error_response("VALIDATION_ERROR", "'catnr' 必须为整数")
1205 entries = fetch_by_catnr(catnr_int, force_refresh=force_refresh)
1206 used_group = f"catnr_{catnr_int}"
1207 else:
1208 entries = fetch_group(group, force_refresh=force_refresh)
1209 used_group = group
1210
1211 injected = 0
1212 if do_inject and entries:
1213 with simulation_engine.lock:
1214 sats = list(simulation_engine.leo_satellites) + list(simulation_engine.meo_satellites)
1215 injected = inject_tle_into_constellation(entries, sats)
1216
1217 first_epoch = entries[0][3] if entries else ""
1218 return ok({
1219 "group": used_group,
1220 "entry_count": len(entries),
1221 "injected": injected,
1222 "first_epoch": first_epoch,
1223 "supported_groups": SUPPORTED_GROUPS,
1224 })
1225 except Exception:

Callers

nothing calls this directly

Calls 6

error_responseFunction · 0.90
fetch_by_catnrFunction · 0.90
fetch_groupFunction · 0.90
okFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected