Skip to content

Instantly share code, notes, and snippets.

@johannesboyne
Created March 19, 2024 08:06
Show Gist options
  • Save johannesboyne/10001cad1f17773548021acb41a31a8a to your computer and use it in GitHub Desktop.
Save johannesboyne/10001cad1f17773548021acb41a31a8a to your computer and use it in GitHub Desktop.
import requests
# CONFIG
token = "" # Add your github token here
repo = "microsoft/fluentui" # the repo you want to check
location_check = None # "Germany" # if you want to check for a specific location
payload = {}
headers = {"Authorization": f"Bearer {token}"}
iteration_start = 0
iteration = 1 + iteration_start
stars_remaining = True
profile_list = []
request_count = 0
def check_api_limit():
if request_count > 1000:
print("soft stop after 1000 requests")
exit(1)
while stars_remaining:
check_api_limit()
url = f"https://api.github.com/repos/{repo}/stargazers?page={iteration}"
response = requests.request("GET", url, headers=headers, data=payload)
request_count += 1
json = response.json()
if json and not len(json) and json["message"].startswith("API rate limit exceeded"):
print("API rate limit exceeded")
break
if len(json) < 25 or iteration > (100 + iteration_start):
print(f"stopped after {iteration} iterations")
stars_remaining = False
for user in json:
profile_list.append(user["url"])
iteration += 1
for profile in profile_list:
check_api_limit()
url = profile
response = requests.request("GET", url, headers=headers, data=payload)
request_count += 1
json = response.json()
if location_check:
if json["location"] == location_check:
print(f"------- {location_check} --------")
print(f"Name: \t{json['name']} \t{json['email']} \t{json['html_url']}")
else:
print(
f"Name: \t{json['name']} \t{json['email']} \t{json['html_url']} \t{json['location']}"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment