KeyHunter parser v10 + 18 scanners + tests (synthetic fixtures only, no keys/db/tokens)
This commit is contained in:
44
eternal_export.py
Normal file
44
eternal_export.py
Normal file
@@ -0,0 +1,44 @@
|
||||
"""Eternal export: rewrite data/working_keys.txt with all live keys every 10 min.
|
||||
Piggybacks on export_working.py logic (inline, single file)."""
|
||||
import os
|
||||
KF_BASE = os.path.dirname(os.path.abspath(__file__))
|
||||
os.makedirs(os.path.join(KF_BASE, "data"), exist_ok=True)
|
||||
import sqlite3
|
||||
import time
|
||||
import os
|
||||
|
||||
DB = os.environ.get("KF_DB") or os.path.join(KF_BASE, "data", "keys.db")
|
||||
OUT = "data/working_keys.txt"
|
||||
INTERVAL = 600
|
||||
|
||||
|
||||
def export():
|
||||
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 = [f"{ts} | {p} | {v} | {pl or ''} | {pr or ''} | remaining={rem or ''}"
|
||||
for v, p, pl, pr, rem in rows]
|
||||
tmp = OUT + ".tmp"
|
||||
with open(tmp, "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(lines) + "\n")
|
||||
os.replace(tmp, OUT)
|
||||
return len(lines)
|
||||
|
||||
|
||||
def main():
|
||||
print(time.strftime("[%H:%M:%S]") + " eternal export start (10 min)", flush=True)
|
||||
while True:
|
||||
try:
|
||||
n = export()
|
||||
print(time.strftime("[%H:%M:%S]") + f" exported {n} live keys", flush=True)
|
||||
except Exception as e:
|
||||
print(time.strftime("[%H:%M:%S]") + f" ERR {e}", flush=True)
|
||||
time.sleep(INTERVAL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user