Last active
March 31, 2019 10:38
-
-
Save gabyfle/548309611863964ae01355e51841d4fe to your computer and use it in GitHub Desktop.
Gets particular user's languages statistics, based on owned repositeries. Gets owned repositeries number.
This file contains 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 | |
/** | |
* Gets github stats from Github's API | |
* @author Gabriel Santamaria <gaby.santamaria@outlook.fr> | |
*/ | |
$github_user = "Gabyfle"; | |
$github_token = "YOURGITHUBTOKEN"; | |
$get_options = [ | |
'http' => [ | |
'method' => 'GET', | |
'header' => [ | |
'User-Agent: github-stats (Made by Gabyfle)' | |
] | |
] | |
]; | |
$context = stream_context_create($get_options); | |
/* Getting repositery number */ | |
$jsonurl = "https://api.github.com/users/" . $github_user . "?access_token=" . $github_token; | |
$json = file_get_contents($jsonurl, false, $context); | |
$user = json_decode($json, true); | |
$reposNumber = $user["public_repos"]; | |
/* Getting languages statistics */ | |
$languages = []; /* Languages stats table */ | |
$jsonurl = "https://api.github.com/users/" . $github_user . "/repos?access_token=" . $github_token; | |
$json = file_get_contents($jsonurl, false, $context); | |
$repositeries = json_decode($json, true); | |
foreach ($repositeries as $key => $value) { | |
$jsonurl = $value["languages_url"] . "?access_token=" . $github_token; | |
$json = file_get_contents($jsonurl, false, $context); | |
$stats = json_decode($json, true); | |
foreach ($stats as $key => $value) { | |
$languages[$key] = $languages[$key] + $value; | |
} | |
} | |
echo $reposNumber . ' maintened projects'; | |
var_dump($languages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment