-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
28 lines (24 loc) · 778 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import requests
import argparse
parser = argparse.ArgumentParser(description="Query API",
formatter_class = argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("token", help = "PAT token for querying")
args = parser.parse_args()
headers = {"Authorization": "token " + args.token }
QUERY = """
{
rateLimit {
remaining
resetAt
}
}
"""
request = requests.post('https://api.github.com/graphql', json={'query': QUERY}, headers=headers)
response = request.json()
if request.status_code == 200:
limit = response["data"]["rateLimit"]
remaining = limit["remaining"]
reset = limit["resetAt"]
print("Limit: %d\nResets at: %s" % (remaining, reset) )
else:
raise Exception("Error (%d) %s" % (request.status_code, response["message"]))