# app.py - мини-реестр: показывает таблицу из файла data.csv
import csv
from html import escape
from http.server import BaseHTTPRequestHandler, HTTPServer
TITLE = "Реестр остатков" # заголовок страницы - замените на свой
DATA_FILE = "/opt/miniapp/data.csv" # файл с данными
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/health": # служебная проверка: программа жива?
self.send_response(200)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.end_headers()
self.wfile.write(b"OK")
return
# файл читается при каждом обращении к странице
with open(DATA_FILE, encoding="utf-8") as f:
rows = list(csv.reader(f, delimiter=";"))
html = "<html><head><meta charset='utf-8'>"
html += "<title>" + TITLE + "</title></head><body>"
html += "<h1>" + TITLE + "</h1>"
html += "<table border='1' cellpadding='5'>"
for i, row in enumerate(rows):
tag = "th" if i == 0 else "td" # 1-я строка файла - заголовки
html += "<tr>"
for cell in row:
html += "<" + tag + ">" + escape(cell) + "</" + tag + ">"
html += "</tr>"
html += "</table><p>Версия 1.0</p></body></html>"
self.send_response(200)
self.send_header("Content-Type", "text/html; charset=utf-8")
self.end_headers()
self.wfile.write(html.encode("utf-8"))
HTTPServer(("127.0.0.1", 8000), Handler).serve_forever()