Skip to content

Instantly share code, notes, and snippets.

@voxpelli
Created June 26, 2018 15:02
Show Gist options
  • Save voxpelli/02f1655a372b72860c583835b35c30f0 to your computer and use it in GitHub Desktop.
Save voxpelli/02f1655a372b72860c583835b35c30f0 to your computer and use it in GitHub Desktop.
Download Gravatars for all authors of a git repo and save in folder. Useful when combined with Gource. Node.js CLI script.
#!/usr/bin/env node
'use strict';
// Inspired by https://github.com/acaudwell/Gource/wiki/Gravatar-Example
const { execSync } = require('child_process');
const crypto = require('crypto');
const https = require('https');
const fs = require('fs');
const size = 90;
const outputDir = '.avatars';
const authors = execSync('git log --pretty=format:"%ae|%an"', { encoding: 'utf8' });
const reducedAuthors = authors.split('\n').reduce((result, item) => {
item = item.trim();
if (item === '') { return result; }
const [ email, author ] = item.split('|')
const preparedEmail = email.trim().toLowerCase();
result[preparedEmail] = author;
return result;
}, {});
Object.keys(reducedAuthors).forEach(email => {
const shasum = crypto.createHash('md5');
shasum.update(email);
const hash = shasum.digest('hex');
const url = `https://www.gravatar.com/avatar/${hash}?d=identicon&s=${size}`;
https.get(url, res => {
res.pipe(fs.createWriteStream(outputDir + '/' + reducedAuthors[email] + '.jpg'));
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment