from datetime import datetime from pydantic import BaseModel class Speedtest(BaseModel): type: str timestamp: datetime ping: "Ping" download: "Bandwidth" upload: "Bandwidth" isp: str interface: "Interface" server: "Server" result: "Result" @classmethod def from_json(cls, data: dict) -> "Speedtest": return cls( type=data["type"], timestamp=datetime.fromisoformat(data["timestamp"]), ping=Ping(**data["ping"]), download=Bandwidth(**data["download"]), upload=Bandwidth(**data["upload"]), isp=data["isp"], interface=Interface(**data["interface"]), server=Server(**data["server"]), result=Result(**data["result"]) ) class Bandwidth(BaseModel): bandwidth: float bytes: int elapsed: int latency: "Latency" class Interface(BaseModel): internalIp: str name: str macAddr: str isVpn: bool externalIp: str class Ping(BaseModel): jitter: float latency: float low: float high: float class Latency(BaseModel): iqm: float low: float high: float jitter: float class Server(BaseModel): id: str name: str location: str country: str host: str port: int ip: str class Result: id: str url: str persisted: bool @property def image(self): return self.url + ".png"