Contenu connexe
Similaire à Social networks analisys - github API (20)
Social networks analisys - github API
- 37. Рейтинг пользователей по репозиториям – код require_once('php-github-api/lib/phpGitHubApi.php'); $github = new phpGitHubApi(); $repositories = array( array('jquery', 'jquery'), array('madrobby', 'scriptaculous'), array('jashkenas', 'coffee-script'), array('yui', 'yui3'), array('sstephenson', 'prototype'), array('mootools', 'mootools-core') ); function add(&$array, $key, $value){ if (!array_key_exists($key, $array)) { $array[$key] = 0; } $array[$key] += $value; } foreach ($repositories as $repository) { list($user, $reponame) = $repository; echo "Processing repository '$reponame' of user '$user'" . PHP_EOL; echo 'Getting watchers' . PHP_EOL; $watchers = $github->getRepoApi()->getRepoWatchers($user, $reponame); foreach ($watchers as $watcher) { add($rating, $watcher, 10); } echo 'Getting contributors' . PHP_EOL; $contributors = $github->getRepoApi()->getRepoContributors($user, $reponame); foreach ($contributors as $contributor) { add($rating, $contributor['login'], $contributor['contributions']); } } asort($rating); foreach ($rating as $person => $ratingValue) { echo implode(',', array($person, $ratingValue)) . PHP_EOL; }