diff --git a/gen-list-html.py b/gen-list-html.py new file mode 100755 index 0000000..31ba3d0 --- /dev/null +++ b/gen-list-html.py @@ -0,0 +1,166 @@ +#!/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 = """ + + + + + + 仓库内容 + + + +
""" + + # 创建标签栏 + for table_name in table_data.keys(): + html += f'' + + html += "
\n " + + # 渲染每个表格的内容 + for table_name, rows in table_data.items(): + html += f'
' + html += f"

{table_name}

" + + # 表格外层包裹 div,启用水平滚动 + html += '
' + html += "" + + # 表头 + if rows: + html += "" + for column in rows[0].keys(): + html += f"" + html += "" + + # 表格数据 + for row in rows: + html += "" + for column in row.keys(): + html += f"" + html += "" + + html += "
{column}
{row[column]}
" + html += "
" # 结束 .table-wrapper + html += "
" + + # 添加 JavaScript 以实现标签切换功能 + html += """ + + + +""" + + dir = os.path.dirname(filename) + if not os.path.exists(dir): + os.makedirs(dir) + # 保存为静态 HTML 文件 + with open(filename, "w", encoding="utf-8") as f: + f.write(html) + + +if __name__ == "__main__": + db = "data/deb.db" + filename="deb/list/index.html" + table_data = fetch_table_data(db) + generate_html(table_data, filename) diff --git a/run.sh b/run.sh index 52c7013..cf09187 100755 --- a/run.sh +++ b/run.sh @@ -23,3 +23,6 @@ sed -i "s|\./|\.\./|g" deb/tmpPackages # generate the Release file gen_release deb/amd64 gen_release deb/arm64 + +# generate the html +./gen-list-html.py \ No newline at end of file