Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
github_statistic.php
<?php
$user_name = 'big-shark';
$client_id = '';
$client_secret = '';
function github($url, $query = array())
{
global $client_id, $client_secret, $user_name;
$query['client_id'] = $client_id;
$query['client_secret'] = $client_secret;
$url = 'https://api.github.com/'.$url.'?'.http_build_query($query);
echo $url.PHP_EOL;
echo $file = '/tmp/'.md5($url).PHP_EOL;
if(!file_exists($file))
{
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_HEADER, false);
curl_setopt($c, CURLINFO_HEADER_OUT, true);
curl_setopt($c, CURLOPT_HTTPHEADER, ["User-Agent: ".$user_name, "Accept: application/vnd.github.v3+json", "Content-Type: application/json; charset=utf-8"]);
$content = curl_exec($c);
$code = curl_getinfo($c, CURLINFO_HTTP_CODE);
if($code != 200 and $code != 404)
{
var_dump(curl_getinfo($c));
die($content);
}
curl_close ($c);
file_put_contents($file, $content);
}
else
{
$handle = fopen($file, "r");
$content = fread($handle, filesize($file));
fclose($handle);
unset($handle);
}
return $content === FALSE ? FALSE : json_decode($content);
}
$keywords = [];
for($page = 1; $page; $page++) {
$starred = github('users/'.$user_name.'/starred', ['page' => $page]);
if(!$starred) break;
foreach ($starred as $repository) {
//if($repository->language !== 'PHP')
// continue;
$composer = github('repos/'.$repository->full_name.'/contents/composer.json');
if($composer === false or (isset($composer->message) and $composer->message === 'Not Found')) //404
continue;
$json = json_decode(base64_decode($composer->content));
if(isset($json->keywords))
{
/*
foreach ($json->keywords as $keyword) {
if(!isset($keywords[$keyword]))
$keywords[$keyword] = [];
$keywords[$keyword][] = $repository->full_name;
}
*/
$keywords = array_merge($keywords, $json->keywords);
}
}
}
$counts = array_count_values($keywords);
arsort($counts);
print_r($counts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.