有没有什么方法可以下载用户的所有github存储库?

时间:2018-03-23 10:15:51

标签: php

有没有办法自动从特定用户下载所有存储库?

也许有一个简单的PHP脚本或Windows应用程序/工具?

P.S。请不要链接API库,我只想要普通计算机用户,而不是自己构建工具。

1 个答案:

答案 0 :(得分:1)

似乎PHP的代码可以完成这项工作(无需安装API库或花费很多时间):

Function Download_all_github_files($github_username){
    set_time_limit(0); $final_url = 'http://github.com/' . $github_username . '?tab=repositories'; $folder = basename($github_username); if (!file_exists($folder)){ mkdir($folder, 0755, true);} 
    preg_match_all('/\<a href=\"(.*?)\" itemprop\=\"name/i',get_data($final_url),$n); if(false) exit(var_dump(get_data($final_url)));
    foreach ($n[1] as $each_Url){file_put_contents(__DIR__."/".$folder."/".basename($each_Url).".zip", get_data('https://github.com'.$each_Url.'/archive/master.zip'));}
    echo 'Downloading finished. Open <a href="./'.$folder.'">folder</a>';
    } Function get_data($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 Safari/534.30"); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 30);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 9); $follow_allowed= ( ini_get('open_basedir') || ini_get('safe_mode')) ? false:true; if ($follow_allowed){curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);}$output = curl_exec($ch); curl_close($ch); return $output;
}

用法:

echo Download_all_github_files("github_username");