stdout.py 450 B

1234567891011121314151617181920
  1. import logging
  2. import datetime
  3. import json
  4. from dataclasses import asdict
  5. logger = logging.getLogger(__name__)
  6. class DateTimeEncoder(json.JSONEncoder):
  7. def default(self, z):
  8. if isinstance(z, datetime.datetime):
  9. return z.isoformat()
  10. else:
  11. return super().default(z)
  12. class JSONOutput:
  13. def write(self, values: set):
  14. for measurement in values:
  15. d = asdict(measurement)
  16. print(json.dumps(d, cls=DateTimeEncoder))