Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cmgeuze
Created May 1, 2020 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmgeuze/d624c86bc7d9930cd4c26ba58ec62445 to your computer and use it in GitHub Desktop.
Save cmgeuze/d624c86bc7d9930cd4c26ba58ec62445 to your computer and use it in GitHub Desktop.
Python script to download repositories
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