formatted html
This commit is contained in:
parent
3a14a55ede
commit
d7a1026ad1
4 changed files with 90 additions and 23 deletions
|
@ -4,7 +4,7 @@
|
|||
{
|
||||
"id": "sensor_001",
|
||||
"type": "temperature",
|
||||
"unit": "C",
|
||||
"unit": "°C",
|
||||
"readings": [
|
||||
{ "ts": 1747814400, "value": 22.5 },
|
||||
{ "ts": 1747818000, "value": 23.0 },
|
||||
|
|
BIN
webserver/favicon.ico
Normal file
BIN
webserver/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 422 KiB |
|
@ -1,4 +1,5 @@
|
|||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
# Opening JSON file
|
||||
|
@ -7,36 +8,57 @@ f = open("data.json")
|
|||
# returns JSON object as a dictionary
|
||||
data = json.load(f)
|
||||
sensors = dict()
|
||||
sensorid = None
|
||||
sensortype = None
|
||||
sensorunit = None
|
||||
sensorreadings = None
|
||||
readings = None
|
||||
|
||||
# Iterating through the json list
|
||||
for i in data["sensors"]:
|
||||
sensorid = i["id"]
|
||||
sensors[sensorid] = [i["type"], i["unit"], i["readings"]]
|
||||
# if i["type"] == "temperature":
|
||||
# readings = i["readings"]
|
||||
|
||||
sensors[i["id"]] = [i["type"], i["unit"], i["readings"]]
|
||||
|
||||
# Closing file
|
||||
f.close()
|
||||
|
||||
html = ""
|
||||
htmldata = ""
|
||||
|
||||
for i in sensors:
|
||||
type = sensors[i][0]
|
||||
unit = sensors[i][1]
|
||||
readings = f"{sensors[i][2][0]["ts"]}: {sensors[i][2][0]["value"]} {unit}"
|
||||
html += f"""
|
||||
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}<br>"
|
||||
htmldata += f"""
|
||||
<p>Id: {i}</p>
|
||||
<p>Type: {type}</p>
|
||||
<p>Readings: {readings}</p>
|
||||
<p>Readings:</p>
|
||||
<div style="margin-left: 40px;">
|
||||
{readings}
|
||||
</div>
|
||||
<p>---------------------------------------------</p>
|
||||
"""
|
||||
|
||||
html = f"""
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Sensor Data</title>
|
||||
<style>
|
||||
* {{
|
||||
font-family: 'Times New Roman';
|
||||
font-size: 18px;
|
||||
color: white;
|
||||
background: #1C1C1C;
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{htmldata}
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
class MyHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue