-
Notifications
You must be signed in to change notification settings - Fork 12
/
update.js
119 lines (108 loc) · 2.89 KB
/
update.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const fs = require('fs');
const github = require('octonode');
const Twit = require('twit');
const people = require('./people.json').people;
const twitterCredentials = require('./twitter-keys');
const client = github.client();
const ghsearch = client.search();
const T = new Twit(twitterCredentials);
const peopleLookup = {};
for (let person of people) {
peopleLookup[person.github] = person;
}
/**
* get user info via Github API
* @param {Object} options
* @return {Promise} a promise
*/
function searchUser(options) {
return new Promise((resolve, reject) => {
ghsearch.users(options, function(err, result, header) {
if (err) reject(Error('error in getting users'));
resolve(result.items);
});
});
}
// update the list via github api
function updatePeople() {
const a = [...Array(10).keys()];
Promise.all(
a.map((value, index) => {
return searchUser({
q: '+type:user+followers:>100',
sort: 'followers',
order: 'desc',
per_page: 100,
page: index + 1,
});
})
)
.then((results) => {
const users = [].concat(...results).map((person) => {
const ghHandle = person.login;
const found = peopleLookup[ghHandle] || {};
return {
github: ghHandle,
name: found.name || '',
company: found.company || '',
bio: found.bio || '',
twitter: found.twitter || '',
medium: found.medium || '',
blog: found.blog || '',
tech: found.keywords || [],
};
});
writeToJSON(users);
})
.catch((err) => {
console.log(err);
});
}
// really simple heuristic that might be wrong... but a lot
// of people are using the same handle for github and twitter
// another one that's not used here is firstname_lastname
function isPotentialMatch(twitterInfo, person) {
let url;
let entities = twitterInfo.entities;
if (entities && entities.url) {
url = entities.url.urls[0].expanded_url;
if (url && url.includes(`github.com/${person.github}`)) {
return true;
}
if (url === person.blog) return true;
}
// if they don't have that many followers, either this is not
// the right one or they are not active, either way can be ignored
if (twitterInfo.followers_count > 500) {
return true;
}
return false;
}
async function updateTwitter() {
for (let person of people) {
if (!person.twitter) {
const info = await T.get('users/show', {
screen_name: person.github,
});
data = info.data;
if (isPotentialMatch(data, person)) {
person.twitter = person.github;
}
}
}
return people;
}
function writeToJSON(people) {
fs.writeFileSync(
'people.json',
JSON.stringify({ people: people }, null, 2),
'utf-8',
(err) => {
if (err) throw err;
}
);
}
// updateGithub();
updateTwitter().then((people) => {
writeToJSON(people);
});