-
-
Save cmgeuze/d624c86bc7d9930cd4c26ba58ec62445 to your computer and use it in GitHub Desktop.
Python script to download repositories
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
from github import Github | |
import pygit2, os, time | |
ACCESS_TOKEN = '<your Github access token>' | |
g = Github(ACCESS_TOKEN) | |
def search_github(keywords): | |
rate_limit = g.get_rate_limit() | |
rate = rate_limit.search | |
if rate.remaining == 0: | |
print(f'You have 0/{rate.limit} API calls remaining. Reset time: {rate.reset}') | |
return | |
else: | |
print(f'You have {rate.remaining}/{rate.limit} API calls remaining') | |
query = '+'.join(keywords) + '+in:readme+in:description' | |
result = g.search_repositories(query, 'stars', 'desc') | |
print(f'Found {result.totalCount} repo(s)') | |
for repo in result: | |
time.sleep(0.1) #prevent rate limit | |
print(f'{repo.clone_url}, {repo.stargazers_count} stars') | |
if not os.path.exists("<local folder>" + repo.name): | |
pygit2.clone_repository(repo.clone_url, "<local folder>" + repo.name) | |
if __name__ == '__main__': | |
keywords = ['delphi'] | |
search_github(keywords) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment