```python import sqlite3 from fastapi import FastAPI from fastapi.responses import HTMLResponse from pydantic import BaseModel app = FastAPI() DB_FILE = "db.sqlite" class ServerData(BaseModel): timestamp: int static_hostname: str machine_id: str operating_system: str uptime: str used_disk: str def init_db(): conn = sqlite3.connect(DB_FILE) cursor = conn.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS servers ( id INTEGER PRIMARY KEY AUTOINCREMENT, timestamp INTEGER, static_hostname TEXT, machine_id TEXT UNIQUE, operating_system TEXT, uptime TEXT, used_disk TEXT ) """) conn.commit() conn.close() @app.on_event("startup") def startup(): init_db() @app.get("/", response_class=HTMLResponse) def root(): conn = sqlite3.connect(DB_FILE) cursor = conn.cursor() cursor.execute(""" SELECT id, timestamp, static_hostname, machine_id, operating_system, uptime, used_disk FROM servers """) rows = cursor.fetchall() conn.close() html = "
| id | timestamp | static_hostname | machine_id | operating_system | uptime | used_disk |
|---|---|---|---|---|---|---|
| {col} | " for col in row) + "