forked from GENBUS760/Lab02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_github.py
More file actions
36 lines (27 loc) · 992 Bytes
/
Copy path05_github.py
File metadata and controls
36 lines (27 loc) · 992 Bytes
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
29
30
31
32
33
34
35
36
#!/usr/bin/env python
import json # to parse JSON
import requests # to make HTTP requests
import argparse # to parse command-line arguments
import time
if __name__ == "__main__":
url_1 = "https://api.github.com/emaadmanzoor"
r = requests.get(url_1)
print(r.status_code)
print(r.json())
url_2 = "https://api.github.com/users/emaadmanzoor"
r = requests.get(url_2)
print(r.status_code)
for key, value in r.json().items():
print(key, value)
print(r.headers)
reset_time = r.headers["x-ratelimit-reset"]
print("Rate limit resets at:", reset_time)
remaining = r.headers["x-ratelimit-remaining"]
print("API calls remaining:", remaining)
current_time = time.time()
reset_time = int(reset_time) # the API gives you a string, not an integer
remaining_time = reset_time - current_time
print("Remaining time (seconds)",
remaining_time)
print("Sleeping until reset...")
time.sleep(remaining_time)