Skip to content

Commit 1cda1d5

Browse files
committed
Dual-publish compat: coerce Time fields to strings only for Go server
1 parent cfa4395 commit 1cda1d5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

publishers/usgs_eq/usgs_eq_publisher.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def parse_earthquake(feature: dict) -> dict | None:
139139
"magnitude": float(mag) if mag is not None else "NaN",
140140
"magType": mag_type or "unknown",
141141
"place": place or "Unknown location",
142-
"eventTime": str(event_time_ms),
143-
"updatedTime": str(updated_ms),
142+
"eventTime": event_time_ms,
143+
"updatedTime": updated_ms,
144144
"latitude": float(lat),
145145
"longitude": float(lon),
146146
"depth_km": float(depth_km) if depth_km is not None else 0.0,
@@ -204,6 +204,7 @@ def __init__(self):
204204
"OSH_BASE_URL",
205205
f"https://{self.osh_address}/{self.osh_root}/api",
206206
)
207+
self._coerce_time_to_str = "csapi-go" in self._base_url
207208
self._auth = "Basic " + base64.b64encode(
208209
f"{self.osh_user}:{self.osh_pass}".encode()).decode()
209210

@@ -243,6 +244,13 @@ def _post_observation(self, obs: dict):
243244
"""POST an observation to the server."""
244245
import ssl
245246

247+
# Go CSAPI server requires Time fields as strings
248+
if self._coerce_time_to_str:
249+
r = obs.get("result", {})
250+
for key in ("eventTime", "updatedTime"):
251+
if key in r and not isinstance(r[key], str):
252+
r[key] = str(r[key])
253+
246254
url = f"{self._base_url}/datastreams/{self._ds_id}/observations"
247255
body = json.dumps(obs).encode()
248256

0 commit comments

Comments
 (0)