20 lines
847 B
Python
20 lines
847 B
Python
import urllib.request, json
|
|
req = urllib.request.Request('http://127.0.0.1:5803/api/keys')
|
|
data = json.loads(urllib.request.urlopen(req, timeout=10).read())
|
|
print(f"{'key':6} {'weekly':15} {'monthly':15} {'rolling':15} {'workspace':40}")
|
|
print('-'*95)
|
|
for k in data['keys']:
|
|
print(f"{k['key_id']:6} "
|
|
f"{k['weekly']['status']:15} "
|
|
f"{k['monthly']['status']:15} "
|
|
f"{k['rolling']['status']:15} "
|
|
f"{k['workspace_id'][:40]:40}")
|
|
|
|
best = None
|
|
for k in data['keys']:
|
|
if (k['weekly']['status'] == 'ok' and
|
|
k['monthly']['status'] == 'ok' and
|
|
k['rolling']['status'] == 'ok'):
|
|
if best is None or k['weekly']['usage_percent'] < best['weekly']['usage_percent']:
|
|
best = k
|
|
print('\nBEST:', best['key_id'] if best else 'NONE', '- all weekly rate-limited' if not best else '') |