diff weather_server/types.py @ 21:beb42c835c52

Make weather server handle arbitrary data: - Make logfile record arbitrary BSONs - Make server handlers OK with same - Make location type a normal class rather than attrs; have it handle its own logger. - Bump version number.
author Paul Fisher <paul@pfish.zone>
date Sat, 19 Oct 2019 18:40:48 -0400
parents 52ef21607b31
children b77c8e7d2742
line wrap: on
line diff
--- a/weather_server/types.py	Sun Oct 13 18:44:12 2019 -0400
+++ b/weather_server/types.py	Sat Oct 19 18:40:48 2019 -0400
@@ -6,7 +6,8 @@
 
 import attr
 
-from . import common
+
+T = t.TypeVar('T')
 
 
 def c_to_f(c: float) -> float:
@@ -51,12 +52,9 @@
     def dew_point_f(self) -> float:
         return c_to_f(self.dew_point_c)
 
-    def as_dict(self) -> t.Dict[str, t.Any]:
-        return attr.asdict(self, recurse=False)
-
     @classmethod
-    def from_now(cls, **kwargs) -> 'Reading':
-        return cls(ingest_time=common.utc_now(), **kwargs)
+    def from_dict(cls: t.Type[T], d: t.Dict[str, t.Any]) -> T:
+        return cls(**{f.name: d[f.name] for f in attr.fields(cls)})
 
     @property
     def _gamma(self) -> float: