from http.server import BaseHTTPRequestHandler, HTTPServer
from datetime import datetime
import json
# Opening JSON file
f = open("data.json")
# returns JSON object as a dictionary
data = json.load(f)
sensors = dict()
# Iterating through the json list
for i in data["sensors"]:
sensors[i["id"]] = [i["type"], i["unit"], i["readings"]]
# Closing file
f.close()
htmldata = ""
for i in sensors:
type = sensors[i][0]
unit = sensors[i][1]
readings = ""
sensorrange = len(sensors[i][2]) if len(sensors[i][2]) < 5 else 4
for j in range(sensorrange):
ts = sensors[i][2][j]["ts"]
time = datetime.fromtimestamp(ts).strftime("%d.%m.%Y %H:%M.%S")
value = sensors[i][2][j]["value"]
readings += f"{time}: {value}{unit}
"
htmldata += f"""
Id: {i}
Type: {type}
Readings:
---------------------------------------------
""" html = f"""