duppr_analysis/experiment_code/minor_revision/test_rate_limit.py

28 lines
867 B
Python

# coding:utf-8
import urllib2
import json
import time
tokens = {
"token 623d83b977ead9c6389e607b0e0ae0088e8e27a2",
"token 3799a0e20b6aeb7cb88428b9527aed5a2b09e99e",
"token 302c872edc4a37e563de72986e09749b12196c88",
"token 9322fbadda497df4d426a472bfca4552a221f185",
"token f1f4c6d2ec5b2a90900bafc8ae8fe149346612ad"
}
send_headers = {"Content-Type":"application/json"}
for token in tokens:
send_headers["Authorization"] = token
print send_headers
req = urllib2.Request("https://api.github.com/rate_limit",headers = send_headers)
result = urllib2.urlopen(req,timeout=20)
raw_data = result.read().decode('utf-8')
rl = json.loads(raw_data)
remaining = rl["rate"]["remaining"]
reset = rl["rate"]["reset"]
print remaining, reset - time.time()
speed = (5000-remaining) *1.0 / (3600 - (reset - time.time()))
print remaining, speed * (reset - time.time())