-
Notifications
You must be signed in to change notification settings - Fork 20
/
find-http-only-sites.js
30 lines (28 loc) · 1.22 KB
/
find-http-only-sites.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
// Tool to run periodically to find sites that are only available over HTTP.
const sites = require('./sites.json');
const cheerio = require('cheerio');
const httpSites = require('./http-sites.json');
for (const blog of sites.blogs) {
const protocol = 'https://';
fetch(`${protocol}${blog}`)
.then(res => res.text())
.catch(() => {
console.log(`Failed to load ${protocol}${blog}. Trying http...`);
fetch(`http://${blog}`)
.then(res => res.text())
.then(html => {
const $ = cheerio.load(html);
if (html) {
console.log(`Loaded ${protocol}${blog} with http.`);
// is it in httpSites?
if (!httpSites.sites.includes(blog)) {
console.log(`Adding ${blog} to http-sites.json.`);
httpSites.sites.push(blog);
fs.writeFileSync('./http-sites.json', JSON.stringify(httpSites, null, 2));
} else {
console.log(`${blog} already in http-sites.json.`);
}
}
})
});
}