Files
keyhunter-parser/export_working.py

27 lines
846 B
Python

"""Export all live keys (WORKING/FREE/LIMITED) → data/working_keys.txt
in eternal_v10 format: ts | PROV | val | plan | price | remaining."""
import sqlite3
import time
DB = "data/keys.db"
OUT = "data/working_keys.txt"
db = sqlite3.connect(DB, timeout=120)
c = db.cursor()
c.execute("SELECT val, prov, plan, price, remaining FROM keys "
"WHERE status IN ('WORKING','FREE','LIMITED') "
"ORDER BY prov, val")
rows = c.fetchall()
db.close()
ts = time.strftime("%Y-%m-%dT%H:%M:%S")
lines = []
for val, prov, plan, price, remaining in rows:
lines.append(f"{ts} | {prov} | {val} | {plan or ''} | {price or ''} | remaining={remaining or ''}")
tmp = OUT + ".tmp"
with open(tmp, "w", encoding="utf-8") as f:
f.write("\n".join(lines) + "\n")
import os
os.replace(tmp, OUT)
print(f"exported {len(lines)} live keys -> {OUT}")