Skip to content

Instantly share code, notes, and snippets.

@cmgeuze

cmgeuze/GithubDownload.py Secret

Created May 1, 2020
Embed
What would you like to do?
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