Forked from openp2pdesign/GourceGravatarExample.py
Last active
October 14, 2021 14:34
-
-
Save AJenbo/544aaf50bf691975d6d38b72e0a6ab21 to your computer and use it in GitHub Desktop.
Download git contributor avatars from GitHub and Gravatar for use with Gource
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 | |
// Place in any subfolder of your project, run `php DownloadAvatarsForGource.php` | |
$list = shell_exec('git shortlog -sne'); | |
if (!$list) { | |
return; | |
} | |
$lines = explode("\n", $list); | |
$context = stream_context_create(["http" => ["header" => "User-agent: DownloadAvatarsForGource"]]); | |
foreach ($lines as $line) { | |
$line = trim($line, " 0123456789>"); | |
$line = explode('<', $line); | |
$line = array_filter($line); | |
$user = array_values($line); | |
$user[0] = trim($user[0]); | |
if (!empty($user[1])) { | |
$dataUrl = 'https://api.github.com/search/users?utf8=%E2%9C%93&q='.$user[1].'+in%3Aemail&type=Users'; | |
$data = @file_get_contents($dataUrl, false, $context); | |
if ($data !== false) { | |
$data = json_decode($data, true); | |
if (!empty($data['items'][0]['avatar_url'])) { | |
$image = @file_get_contents($data['items'][0]['avatar_url'], false, $context); | |
if ($image != false) { | |
file_put_contents($user[0].'.png', $image); | |
continue; | |
} | |
} | |
} | |
} | |
$image = @file_get_contents('https://github.com/'.$user[0].'.png', false, $context); | |
if ($image != false) { | |
file_put_contents($user[0].'.png', $image); | |
continue; | |
} | |
if ($user[1]) { | |
$image = @file_get_contents('http://www.gravatar.com/avatar/'.md5($user[1])."?d=identicon&s=256", false, $context); | |
if ($image != false) { | |
file_put_contents($user[0].'.png', $image); | |
continue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment