Files
deepai-code-autoreg/checkin_probe.py
T

73 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""Проверка механики check-in: шлём X-DeepAI-Code-Check-In с nonce из ответа /theos
и замеряем, начисляются ли Theos.
python checkin_probe.py <rounds> [n_accounts]
"""
import json
import sys
import time
import dpcode as D
API = D.API
def hdrs(machine, nonce=None, up=120, pi=1):
h = {"X-DeepAI-Code-Theos": "4",
"X-DeepAI-Code-Instance": __import__("secrets").token_hex(16),
"X-DeepAI-Code-Machine": machine,
"X-DeepAI-Code-Beacon": "v=1.3.0;up=%d;pi=%d;focus=1" % (up, pi)}
if nonce:
h["X-DeepAI-Code-Check-In"] = nonce
return h
def get_theos(s, machine, nonce=None, up=120, pi=1):
r = s.get(API + "/deepai_code/theos", headers=hdrs(machine, nonce, up, pi), timeout=30)
try:
return r.status_code, r.json()
except Exception:
return r.status_code, {"raw": r.text[:150]}
def rows(n):
recs = {}
for line in open(D.BANK, encoding="utf-8"):
line = line.strip()
if not line:
continue
r = json.loads(line)
if r.get("cookies"):
recs[r["email"]] = r
zero = [r for r in recs.values()
if float(((r.get("theos") or {}).get("granted")) or 0) == 0]
return zero[:n]
def main():
rounds = int(sys.argv[1]) if len(sys.argv) > 1 else 3
n = int(sys.argv[2]) if len(sys.argv) > 2 else 2
for rec in rows(n):
email = rec["email"]
machine = rec.get("machine") or D.machine_header(salt=email)
s = D.session_from(rec)
st, d = get_theos(s, machine)
nonce = (d.get("check_in") or {}).get("nonce")
print("%s start bal=%s granted=%s nonce=%s" % (email, d.get("balance"), d.get("granted"),
(nonce or "")[:8]), flush=True)
for i in range(rounds):
time.sleep(5)
st, d = get_theos(s, machine, nonce=nonce, up=120 + i * 5)
new_nonce = (d.get("check_in") or {}).get("nonce")
print(" r%d http=%s bal=%s granted=%s refresh=%s nonce=%s"
% (i, st, d.get("balance"), d.get("granted"), d.get("refresh_at"),
(new_nonce or "")[:8]), flush=True)
if new_nonce:
nonce = new_nonce
rec["theos"] = d
D.append_bank(rec)
if __name__ == "__main__":
main()