Skip to content

Instantly share code, notes, and snippets.

@debuggerx01
Forked from anonymous/git_clone.py
Created August 25, 2018 22:30
Show Gist options
  • Save debuggerx01/94bcaabcd60388981261fae9a4b34929 to your computer and use it in GitHub Desktop.
Save debuggerx01/94bcaabcd60388981261fae9a4b34929 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Filename : clone.py
# @Date : 18-2-6 12:36
# @Author : DebuggerX
import re
import urllib
import subprocess
import os
repositories = []
def get_page(url, index):
html = urllib.urlopen('%s?page=%d' % (url, index)).read()
if html and "Page not found" not in html and 'This organization has no more repositories' not in html:
assert isinstance(html, str)
shtmls = re.findall("href=\".+\" itemprop=\"name codeRepository\"", html)
for shtml in shtmls:
assert isinstance(shtml, str)
repositories.append(shtml[6:shtml.find('" itemprop')])
print("正在分析第%d页" % index)
index += 1
get_page(baseUrl, index)
else:
pass
if __name__ == '__main__':
account = raw_input('请输入github用户名,将分析该账户下所有仓库\n')
baseUrl = 'https://github.com/%s' % account
print("开始分析仓库。。。")
get_page(baseUrl, 1)
print("总共得到%d条仓库信息" % len(repositories))
print("开始抓取各个仓库")
cmd = ''
for repository in repositories:
print('https://github.com%s' % repository)
print('按任意键开始克隆以上所有仓库')
subprocess.call("bash -c 'read' '-n' '1'", shell=True)
for repository in repositories:
os.system('git clone https://github.com%s.git' % repository)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment