forked from lambtron/get-stargazers-emails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (42 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Module dependencies.
*/
var dotenv = require('dotenv');
dotenv.config();
var repo = process.argv[2] || 'segmentio/analytics.js';
var output = process.argv[3] || 'output.csv';
var source = process.argv[4] || 'stargazers';
var github = require('./lib/github');
var co = require('co');
var fs = require('fs');
var ProgressBar = require('progress');
/**
* Do stuff.
*/
co(function *(){
console.log('Fetching '+source+' for repo: '+repo);
var sourceList;
if(source === 'stargazers') {
sourceList = yield github.getStargazers(repo);
} else if(source === 'forkers') {
sourceList = yield github.getForkers(repo);
}
console.log('Fetching user profiles for '+sourceList.length+' '+source);
var bar = new ProgressBar('Profiles [:bar] :percent :etas', {
complete: '=',
incomplete: ' ',
width: 60,
total: sourceList.length
});
for (var i = 0; i < sourceList.length; i++) {
try {
var user = yield github.getEmail(sourceList[i]);
var line = ['"'+user.username+'"', '"'+user.name+'"', '"'+user.email+'"'].join(',') + '\n';
fs.appendFileSync(output, line, { encoding: 'utf8' });
bar.tick();
} catch (e) {
console.error(e);
}
}
console.log('Done writing '+source+' profiles to '+output);
});