summaryrefslogtreecommitdiff
path: root/github-fetch.py
blob: 07bbf52fdbb9dbb531ecbf14781a26dfdde37f92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Print git clone commands for each repository created by a given github
# account.

import requests
import sys

def pages(starturl):
  r = requests.get(starturl)
  yield r
  while 'next' in r.links:
    r = requests.get(r.links['next']['url'])
    yield r

#pgs = list(pages('https://api.github.com/users/cloudfoundry/repos'))
#for page in pgs:
#  for repo in page.json():
#    print('git clone {}'.format(repo['clone_url']))

def cloneurls(accountname):
  starturl = 'https://api.github.com/users/{}/repos'.format(accountname)
  for page in pages(starturl):
    for repo in page.json():
      yield repo['clone_url']

for url in cloneurls(sys.argv[1]):
  print('git clone {}'.format(url))