-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import sqlite3 | ||
import time | ||
from datetime import datetime, timezone | ||
|
||
|
||
def get_db_connection(db_path): | ||
conn = sqlite3.connect(db_path) | ||
conn.row_factory = sqlite3.Row | ||
return conn | ||
|
||
|
||
def fetch_queue_data(conn): | ||
query = """ | ||
SELECT | ||
ROW_NUMBER() OVER (ORDER BY last_started ASC) AS number, | ||
attr_path, | ||
payload | ||
FROM | ||
'queue' | ||
ORDER BY | ||
last_started ASC | ||
""" | ||
return conn.execute(query).fetchall() | ||
|
||
|
||
def generate_html_table(rows): | ||
table_rows = "".join( | ||
f""" | ||
<tr> | ||
<td>{row['number']}</td> | ||
<td>{row['attr_path']}</td> | ||
<td>{row['payload']}</td> | ||
</tr> | ||
""" | ||
for row in rows | ||
) | ||
return table_rows | ||
|
||
|
||
def export_html(db_path): | ||
with get_db_connection(db_path) as conn: | ||
results = fetch_queue_data(conn) | ||
|
||
generated = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC") | ||
|
||
html = f""" | ||
<html> | ||
<head> | ||
<title>nixpkgs-update queue</title> | ||
</head> | ||
<body> | ||
<h1>nixpkgs-update queue</h1> | ||
<h3>this page is updated every 15 minutes, last updated: {generated}</h3> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>number</th> | ||
<th>attribute path</th> | ||
<th>payload</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{generate_html_table(results)} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> | ||
""" | ||
|
||
with open("queue.html", "w") as f: | ||
f.write(html) | ||
|
||
|
||
if __name__ == "__main__": | ||
DB_PATH = "state.db" | ||
while True: | ||
export_html(DB_PATH) | ||
time.sleep(15 * 60) |