#!/usr/bin/env python3 import sqlite3 import os # 获取数据库中所有表的数据 def fetch_table_data(db: str) -> dict: conn = sqlite3.connect(db) conn.row_factory = sqlite3.Row # 使得查询结果可以通过列名访问 cursor = conn.cursor() # 获取数据库中的所有表 cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") tables = cursor.fetchall() # 获取每个表的内容 table_data = {} for table in tables: table_name = table["name"] cursor.execute(f"SELECT * FROM '{table_name}'") table_data[table_name] = cursor.fetchall() conn.close() return table_data # 生成静态 HTML 页面 def generate_html(table_data, filename): html = """
| {column} | " html += "
|---|
| {row[column]} | " html += "