-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
25 lines (21 loc) · 745 Bytes
/
Copy pathparser.py
File metadata and controls
25 lines (21 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import logging
from typing import Optional
from datetime import datetime, timezone
from models import SurveyPoint
logger = logging.getLogger(__name__)
def parse_line(line: str) -> Optional[SurveyPoint]:
"""Parse a single JSON line emitted by the cell_monitor binary."""
line = line.strip()
if not line:
return None
try:
data = json.loads(line)
data["timestamp"] = datetime.now(timezone.utc).isoformat()
return SurveyPoint(**data)
except json.JSONDecodeError as exc:
logger.warning("JSON parse error: %s | raw: %r", exc, line)
return None
except Exception as exc:
logger.warning("Model validation error: %s | raw: %r", exc, line)
return None