Upload deploy/ingest/flights.py with huggingface_hub
Browse files13 unmodified lines14151617181940 unmodified lines606162636465666713 unmodified linesimport urllib.requestOUT = "/data/apps/globe/data"URL = "https://opensky-network.org/api/states/all"UA = "Mozilla/5.0 (compatible; geoevents/1.0; research)"40 unmodified linesexcept Exception as e: # noqa: BLE001print("mil failed:", repr(e)[:120], file=sys.stderr)payload = {"generated": int(time.time()), "count": len(out), "flights": out,"mil": mil, "mil_count": len(mil)}with open(os.path.join(OUT, "flights.json"), "w", encoding="utf-8") as f:json.dump(payload, f, ensure_ascii=False, separators=(",", ":"))emg = sum(1 for f in out if f[7] in ("7700", "7600", "7500"))13 unmodified lines141516171819202140 unmodified lines6263646566676869707172737475767778798081828384858687888913 unmodified linesimport urllib.requestOUT = "/data/apps/globe/data"HIST = os.path.join(OUT, "flight_hist.json")HIST_MAX = 8 # 8 轮 × 20 分钟 ≈ 2.7 小时URL = "https://opensky-network.org/api/states/all"UA = "Mozilla/5.0 (compatible; geoevents/1.0; research)"40 unmodified linesexcept Exception as e: # noqa: BLE001print("mil failed:", repr(e)[:120], file=sys.stderr)# 轨迹:把本轮位置并入历史,保留最近 8 轮,供前端画已飞航迹hist = {}if os.path.exists(HIST):try:with open(HIST, encoding="utf-8") as f:hist = json.load(f)except Exception: # noqa: BLE001hist = {}now = int(time.time())keep = {}for f in out:hexid = f[7]pts = hist.get(hexid) or []# 位移小于 1 km 视为未动,不重复记点if not pts or abs(pts[-1][0] - f[0]) + abs(pts[-1][1] - f[1]) > 0.01:pts.append([f[0], f[1], now])keep[hexid] = pts[-HIST_MAX:]with open(HIST, "w", encoding="utf-8") as f:json.dump(keep, f, separators=(",", ":"))payload = {"generated": now, "count": len(out), "flights": out,"mil": mil, "mil_count": len(mil), "trails": keep}with open(os.path.join(OUT, "flights.json"), "w", encoding="utf-8") as f:json.dump(payload, f, ensure_ascii=False, separators=(",", ":"))emg = sum(1 for f in out if f[7] in ("7700", "7600", "7500"))
deploy/ingest/flights.py+24-2