-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-data.js
51 lines (44 loc) · 1.13 KB
/
get-data.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
#!/bin/node
// Thanks to cloudping.co
// Christoph Wiechert psi-4ward
// https://github.com/mda590/cloudping.co/issues/35#issuecomment-706523186
const fs = require('fs');
const got = require('got');
const cheerio = require('cheerio');
(async function() {
const result = {};
const html = (await got('https://www.cloudping.co/grid/p_50/timeframe/1M'))
.body;
const $ = cheerio.load(html);
const destRegions = $('#app > table > thead > tr > th')
.slice(1)
.map((i, el) => {
const splt = $(el)
.text()
.split(' ');
return splt.pop();
})
.toArray();
$('#app > table > tbody > tr').map((i, el) => {
const splt = $(el)
.find('th')
.first()
.text()
.split(' ');
const src = splt.pop();
$(el)
.find('td')
.map((i, el) => $(el).text())
.toArray()
.map((v, i) => {
if (!result[src]) {
result[src] = {};
}
result[src][destRegions[i]] = +v;
});
});
const json = JSON.stringify(result, null, 2);
fs.writeFile('data.json', `${json}\n`, function(err) {
if (err) return console.log(err);
});
})();