Skip to content

Instantly share code, notes, and snippets.

@edgardleal
Created June 24, 2022 18:16
Show Gist options
  • Save edgardleal/7bccf44bffe1eaf73edf1d602b6ab0d4 to your computer and use it in GitHub Desktop.
Save edgardleal/7bccf44bffe1eaf73edf1d602b6ab0d4 to your computer and use it in GitHub Desktop.
Download gravatar user images from a git repository folder to be used with gource
const fs = require('fs');
const path = require('path');
const shelljs = require('shelljs');
const crypto = require('crypto');
const size = 90;
const output_dir = '.git/avatar';
shelljs.mkdir('-p', output_dir);
const log_command = 'git log --pretty=format:"%ae|%an"';
const logResult = shelljs.exec(log_command, { silent: true });
const logs = Array.from(new Set(logResult.stdout.split(/[\n\r]/).sort()));
console.log('Found %d users', logs.length); // eslint-disable-line
for (let i = 0; i < logs.length; i += 1) {
const item = logs[i];
const [email, name] = item.split('|');
const imagePath = path.join(__dirname, output_dir, `${name}.png`);
if (fs.existsSync(imagePath)) {
continue;
}
const emailHash = crypto.createHash('md5').update(email).digest('hex');
const grav_url = `http://www.gravatar.com/avatar/${emailHash}?d=404&size=${size}`;
console.log('Downloading %s', email); // eslint-disable-line
const result = shelljs.exec(`wget --output-document='${imagePath}' ${grav_url}`, { silent: true });
if (result.stderr.indexOf('ERROR 404') > -1) {
shelljs.exec(`rm '${imagePath}'`);
}
shelljs.exec('sleep 1');
}
const gourceCommand = `gource \
-s 2 \
-1280x720 \
--auto-skip-seconds .1 \
--multi-sampling \
--stop-at-end \
--key \
--highlight-users \
--date-format "%d/%m/%y" \
--hide mouse,filenames \
--file-idle-time 0 \
--max-files 0 \
--background-colour 000000 \
--font-size 25 --user-image-dir ${output_dir}
`
console.log('%s', gourceCommand); // eslint-disable-line
@edgardleal
Copy link
Author

@edgardleal
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment