-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack-repos.js
47 lines (43 loc) · 1.28 KB
/
webpack-repos.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
// Finds popular GitHub Repos that use Webpack
const fetch = require("isomorphic-fetch");
const cheerio = require("cheerio");
const minStar = 100;
const startingURL =
"https://github.com/webpack/webpack/network/dependents?dependents_after=OTQ2ODEzNzk0OQ";
let iterations = 0;
const results = {
"https://github.com/daybrush/moveable": 1315,
"https://github.com/lando/lando": 1471,
};
function getThem(html) {
const $ = cheerio.load(html);
$(".Box-row.d-flex.flex-items-center").map(function (_, el) {
const $0 = cheerio.load(el);
const stars = parseInt($0(".pl-3").text().replace(",", ""), 10);
if (stars >= minStar) {
const href = $0("a.text-bold").attr("href");
results["https://github.com" + href] = stars;
}
});
return $;
}
function clickNext($) {
const next = $('[data-test-selector="pagination"]')
.children()
.last()
.attr("href");
if (next) setTimeout(() => get(next), 2000 + Math.random() * 1000);
else console.log(results);
}
function get(url) {
iterations++;
console.log(`page ${iterations}: ${url}`);
if (iterations % 20 === 0) {
console.log(JSON.stringify(results, null, 2));
}
fetch(url)
.then((res) => res.ok && res.text())
.then((text) => getThem(text))
.then(($) => clickNext($));
}
get(startingURL);