Last active
September 16, 2018 09:40
-
-
Save ohld/a3a67240aa5712c1451d3e38940b33ff to your computer and use it in GitHub Desktop.
Check if a user starred the repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import requests | |
GITHUB_USERNAME = os.getenv("GITHUB_USERNAME") | |
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN") | |
REPOSITORY = os.getenv("REPOSITORY") | |
USERNAME = os.getenv("USERNAME") | |
def check_if_user_starred(username, repository): | |
next_link = "https://api.github.com/repos/{}/stargazers".format(repository) | |
while True: | |
resp = requests.get(next_link, auth=(GITHUB_USERNAME, GITHUB_TOKEN)) | |
logins = [r["login"] for r in resp.json()] | |
if username in logins: | |
return True | |
if "next" not in resp.links: | |
break | |
next_link = resp.links["next"]["url"] | |
time.sleep(1.5) | |
return False | |
if __name__ == '__main__': | |
user_starred = check_if_user_starred(USERNAME, REPOSITORY) | |
print(user_starred) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment