Upload deploy/ingest/satellites.py with huggingface_hub
Browse files1234564 unmodified lines1112131415161718195 unmodified lines252627282930311 unmodified line333435363738394041424344"""卫星星历:抓 Celestrak 的 TLE,输出给前端用 SGP4 实时推算位置。只取三组,够看出"卫星在动"又不至于糊满屏幕:空间站、GPS、气象。"""import jsonimport os4 unmodified linesUA = "Mozilla/5.0 (compatible; GeoEvents/1.0)"GROUPS = [("stations", "空间站"),("gps-ops", "导航"),("weather", "气象"),]5 unmodified linesdef main():sats, errors = [], []for group, label in GROUPS:url = f"https://celestrak.org/NORAD/elements/gp.php?GROUP={group}&FORMAT=tle"try:txt = get(url)1 unmodified lineerrors.append(f"{group}: {type(e).__name__}")continuelines = [x.strip() for x in txt.splitlines() if x.strip()]# TLE 三行一组:名称、第 1 行、第 2 行for i in range(0, len(lines) - 2, 3):name, l1, l2 = lines[i], lines[i + 1], lines[i + 2]if not (l1.startswith("1 ") and l2.startswith("2 ")):continuesats.append({"n": name[:36], "l1": l1, "l2": l2, "g": group, "gl": label})time.sleep(1.2) # Celestrak 建议请求间隔payload = {12345674 unmodified lines1213141516171819202122235 unmodified lines293031323334351 unmodified line3738394041424344454647484950515253"""卫星星历:抓 Celestrak 的 TLE,输出给前端用 SGP4 实时推算位置。五组:空间站、导航、气象、光学亮星、科学。另外星链单独取、按比例抽样——全量一万余颗,全画既算不动也看不清,抽 3000 颗已能铺出真实的星座带。"""import jsonimport os4 unmodified linesUA = "Mozilla/5.0 (compatible; GeoEvents/1.0)"GROUPS = [("stations", "空间站", 0),("gps-ops", "导航", 0),("weather", "气象", 0),("visual", "亮星", 0),("science", "科学", 0),("starlink", "星链", 3000),]5 unmodified linesdef main():sats, errors = [], []for group, label, cap in GROUPS:url = f"https://celestrak.org/NORAD/elements/gp.php?GROUP={group}&FORMAT=tle"try:txt = get(url)1 unmodified lineerrors.append(f"{group}: {type(e).__name__}")continuelines = [x.strip() for x in txt.splitlines() if x.strip()]rows = []# TLE 三行一组:名称、第 1 行、第 2 行for i in range(0, len(lines) - 2, 3):name, l1, l2 = lines[i], lines[i + 1], lines[i + 2]if not (l1.startswith("1 ") and l2.startswith("2 ")):continuerows.append({"n": name[:36], "l1": l1, "l2": l2, "g": group, "gl": label})if cap and len(rows) > cap:step = len(rows) / caprows = [rows[int(i * step)] for i in range(cap)]sats.extend(rows)time.sleep(1.2) # Celestrak 建议请求间隔payload = {
deploy/ingest/satellites.py+15-6