Skip to content

Instantly share code, notes, and snippets.

@ljtill
Last active December 6, 2019 15:33
Show Gist options
  • Save ljtill/533517c90cebf1a2515b12b3a20bad1f to your computer and use it in GitHub Desktop.
Save ljtill/533517c90cebf1a2515b12b3a20bad1f to your computer and use it in GitHub Desktop.
Provides the ability to clone all GitHub repositories
from subprocess import call
import requests
import json
class GitHub:
def repositories(self, token, path):
url = 'https://api.github.com/user/repos?affiliation=owner'
headers = {'Authorization': ('Bearer ' + token)}
try:
response = requests.get(url, headers=headers)
output = (json.loads(response.text))
for r in output:
call(['git', '-C', path, 'clone', r['clone_url']])
except:
print('An error occured.')
return
token = ''
path = ''
git = GitHub()
git.repositories(token, path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment