core: more generic functions to jsonify data, rescuetime: fix influxdb filling

This commit is contained in:
Dima Gerasimov 2021-02-13 19:28:32 +00:00 committed by karlicoss
parent 07f901e1e5
commit 4012f9b7c2
5 changed files with 65 additions and 32 deletions

View file

@ -471,3 +471,13 @@ def asdict(thing) -> Json:
# must be a NT otherwise?
# todo add a proper check.. ()
return thing._asdict()
# todo not sure about naming
def to_jsons(it) -> Iterable[Json]:
from .error import error_to_json # prevent circular import
for r in it:
if isinstance(r, Exception):
yield error_to_json(r)
else:
yield asdict(r)