Spaces:
Running
Running
fix(v4): NOAA Kp feed array-of-objects — parse both shapes (live Kp restored)
Browse filesAdditive, no route/schema change. Signed-off-by: Yachay <yachay@szlholdings.dev>
Co-authored-by: Perplexity Computer Agent <agent@perplexity.ai>
- killinchu_drone_3d_health.py +10 -3
killinchu_drone_3d_health.py
CHANGED
|
@@ -139,11 +139,18 @@ def fetch_spaceweather() -> dict[str, Any]:
|
|
| 139 |
kp = None
|
| 140 |
try:
|
| 141 |
kp_rows = _get_json("https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json")
|
| 142 |
-
#
|
|
|
|
|
|
|
| 143 |
last = kp_rows[-1]
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
out["kp_index"] = kp
|
| 146 |
-
out["kp_time"] = last[0]
|
| 147 |
out["sources"].append({"name": "NOAA SWPC planetary K-index", "live": True,
|
| 148 |
"url": "https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json"})
|
| 149 |
out["live"] = True
|
|
|
|
| 139 |
kp = None
|
| 140 |
try:
|
| 141 |
kp_rows = _get_json("https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json")
|
| 142 |
+
# NOAA SWPC has shipped this feed in two shapes over time; support BOTH:
|
| 143 |
+
# (a) array-of-arrays w/ header row: [["time_tag","Kp_index",...],["...","2.67",...]]
|
| 144 |
+
# (b) array-of-objects (current): [{"time_tag":"...","Kp":2.67,"a_running":12,...}]
|
| 145 |
last = kp_rows[-1]
|
| 146 |
+
if isinstance(last, dict):
|
| 147 |
+
kp_val = last.get("Kp", last.get("kp_index", last.get("kp")))
|
| 148 |
+
kp = float(kp_val)
|
| 149 |
+
out["kp_time"] = last.get("time_tag")
|
| 150 |
+
else:
|
| 151 |
+
kp = float(last[1])
|
| 152 |
+
out["kp_time"] = last[0]
|
| 153 |
out["kp_index"] = kp
|
|
|
|
| 154 |
out["sources"].append({"name": "NOAA SWPC planetary K-index", "live": True,
|
| 155 |
"url": "https://services.swpc.noaa.gov/products/noaa-planetary-k-index.json"})
|
| 156 |
out["live"] = True
|