from requests.auth import HTTPBasicAuth import requests import os import json repos = set() def download_repo(output, name, href): print(f'Cloning {name} {href}') os.system(f'git clone --depth 1 {href} "{output}/{name}"') def get_bitbucket_repos(user,username, password): """Retrieves all bitbucket repos, handles pagination""" var_repos = [] url = "https://api.bitbucket.org/2.0/repositories/{}".format(user) #替换你需要同步的仓库的URL headers = {'Content-Type': 'application/json'} r = requests.get(url, headers=headers) # auth=(username, password), page_result = json.loads(r.text) var_repos += page_result['values'] while 'next' in page_result: url = page_result['next'] r = requests.get(url, headers=headers) #auth=(username, password), page_result = json.loads(r.text) var_repos += page_result['values'] for r in var_repos: name = r['name'] links = r['links']['clone'] href = next(link['href'] for link in links if link['name'] == 'https') print(f'Found repo {name} {href}') repos.add((name, href)) return var_repos if __name__ == "__main__": import argparse #开源项目不需要 username 和 pwd ,私有项目才需要 user = "arlez80" username ="" pwd = "" output = "E:/txh/python/out" get_bitbucket_repos("arlez80",username,pwd) for repo in repos: download_repo(output, *repo)
标签:username,同步,name,批量,repos,开源,href,result,page From: https://www.cnblogs.com/porter/p/17947364