Last active
November 10, 2020 01:46
-
-
Save Zorono/0c06392e4a19a3521dff85bd28b263ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ch = curl_init(); | |
$_ERR_CODES = array( | |
100 => 'Continue', | |
101 => 'Switching Protocols', | |
102 => 'Processing...', | |
200 => 'OK', | |
201 => 'Created', | |
202 => 'Accepted', | |
203 => 'Non-Authoritative Information', | |
204 => 'No Content', | |
205 => 'Reset Content', | |
206 => 'Partial Content', | |
207 => 'Multi-Status', | |
300 => 'Multiple Choices', | |
301 => 'Moved Permanently', | |
302 => 'Found', | |
303 => 'See Other', | |
304 => 'Not Modified', | |
305 => 'Use Proxy', | |
306 => 'Switch Proxy', | |
307 => 'Temporary Redirect', | |
400 => 'Bad Request', | |
401 => 'Unauthorized', | |
402 => 'Payment Required', | |
403 => 'Forbidden', | |
404 => 'Not Found', | |
405 => 'Method Not Allowed', | |
406 => 'Not Acceptable', | |
407 => 'Proxy Authentication Required', | |
408 => 'Request Timeout', | |
409 => 'Conflict', | |
410 => 'Gone', | |
411 => 'Length Required', | |
412 => 'Precondition Failed', | |
413 => 'Request Entity Too Large', | |
414 => 'Request-URI Too Long', | |
415 => 'Unsupported Media Type', | |
416 => 'Requested Range Not Satisfiable', | |
417 => 'Expectation Failed', | |
418 => 'I\'m a teapot', | |
422 => 'Unprocessable Entity', | |
423 => 'Locked', | |
424 => 'Failed Dependency', | |
425 => 'Unordered Collection', | |
426 => 'Upgrade Required', | |
449 => 'Retry With', | |
450 => 'Blocked by Windows Parental Controls', | |
500 => 'Internal Server Error', | |
501 => 'Not Implemented', | |
502 => 'Bad Gateway', | |
503 => 'Service Unavailable', | |
504 => 'Gateway Timeout', | |
505 => 'HTTP Version Not Supported', | |
506 => 'Variant Also Negotiates', | |
507 => 'Insufficient Storage', | |
509 => 'Bandwidth Limit Exceeded', | |
510 => 'Not Extended' | |
); | |
$allowed_errorcodes = array(200, 201, 202, 204); | |
curl_setopt_array($ch, array( | |
CURLOPT_URL => "https://api.github.com/user/starred?page=" . (is_null($_GET["page"]) ? 1 : $_GET["page"]), | |
CURLOPT_CUSTOMREQUEST => 'GET', | |
CURLOPT_CONNECTTIMEOUT => 10, | |
CURLOPT_CONNECTTIMEOUT_MS => 1500, | |
CURLOPT_FORBID_REUSE => 1, | |
CURLOPT_FRESH_CONNECT => 1, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTPHEADER => ['Authorization: token {YOUR_ACCESS_TOKEN}'], | |
CURLOPT_RETURNTRANSFER => True, | |
CURLOPT_SSL_VERIFYHOST => 2, | |
CURLOPT_SSL_VERIFYPEER => 1, | |
CURLOPT_HTTP_VERSION => (explode('HTTP/', $_SERVER['SERVER_PROTOCOL'])[1] === 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0), | |
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] | |
)); | |
$result = curl_exec($ch); | |
if($CURL_ErrorN = curl_errno($ch)) | |
{ | |
switch($CURL_Error = curl_strerror($CURL_ErrorN)) | |
{ | |
case 'Couldn\'t resolve host name': { | |
throw new \Exception("cURL error (" .$CURL_ErrorN. "): " .$CURL_Error. ': ' .mb_strimwidth(curl_getinfo($ch)['url'], 0, 60, "...")); | |
} | |
break; | |
default: { | |
echo "cURL error (" .$CURL_ErrorN. "): " .$CURL_Error. " Retrying..."; | |
$result = curl_exec($ch); | |
} | |
} | |
} | |
for($err = 0; $err < count($allowed_errorcodes); $err++) | |
{ | |
if (($HTTPCode = curl_getinfo($ch, CURLINFO_HTTP_CODE)) == $allowed_errorcodes[$err]) | |
{ | |
break; | |
} | |
else | |
{ | |
continue; | |
} | |
if($err >= count($allowed_errorcodes)) | |
{ | |
throw new \Exception($HTTPCode . ':' . (strlen($result) >= 1 ? $result : 'NULL')); | |
break; | |
} | |
} | |
foreach(json_decode($result, True) as $eachRow) | |
{ | |
$ch2 = curl_init(); | |
curl_setopt_array($ch2, array( | |
CURLOPT_URL => "https://api.github.com/repos/" . $eachRow["full_name"], | |
CURLOPT_CUSTOMREQUEST => 'GET', | |
CURLOPT_CONNECTTIMEOUT => 10, | |
CURLOPT_CONNECTTIMEOUT_MS => 1500, | |
CURLOPT_FORBID_REUSE => 1, | |
CURLOPT_FRESH_CONNECT => 1, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTPHEADER => ['Authorization: token {YOUR_ACCESS_TOKEN}'], | |
CURLOPT_RETURNTRANSFER => True, | |
CURLOPT_SSL_VERIFYHOST => 2, | |
CURLOPT_SSL_VERIFYPEER => 1, | |
CURLOPT_HTTP_VERSION => (explode('HTTP/', $_SERVER['SERVER_PROTOCOL'])[1] === 1.1 ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0), | |
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'] | |
)); | |
$result2 = curl_exec($ch2); | |
if($CURL_ErrorN = curl_errno($ch2)) | |
{ | |
switch($CURL_Error = curl_strerror($CURL_ErrorN)) | |
{ | |
case 'Couldn\'t resolve host name': { | |
throw new \Exception("cURL error (" .$CURL_ErrorN. "): " .$CURL_Error. ': ' .mb_strimwidth(curl_getinfo($ch2)['url'], 0, 60, "...")); | |
} | |
break; | |
default: { | |
echo "cURL error (" .$CURL_ErrorN. "): " .$CURL_Error. " Retrying..."; | |
$result2 = curl_exec($ch2); | |
} | |
} | |
} | |
for($err = 0; $err < count($allowed_errorcodes); $err++) | |
{ | |
if (($HTTPCode = curl_getinfo($ch2, CURLINFO_HTTP_CODE)) == $allowed_errorcodes[$err]) | |
{ | |
break; | |
} | |
else | |
{ | |
continue; | |
} | |
if($err >= count($allowed_errorcodes)) | |
{ | |
throw new \Exception($HTTPCode . ':' . (strlen($result2) >= 1 ? $result2 : 'NULL')); | |
break; | |
} | |
} | |
foreach(json_decode($result2, True) as $eachRow2 => $eachRow2Val) | |
{ | |
$language = "_"; | |
if($eachRow2 == "language") $language = $eachRow2Val; | |
if($eachRow2 == "svn_url") $repoURL = $eachRow2Val; | |
if(strtolower($language) == "NULL" || $language == NULL) echo $repoURL. "<br />"; | |
} | |
curl_close($ch2); | |
} | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment