57 lines
1.5 KiB
JavaScript
57 lines
1.5 KiB
JavaScript
#! /usr/bin/env node
|
|
const fs = require('fs');
|
|
const axios = require('axios');
|
|
const captureWebsite = require('capture-website');
|
|
const mustache = require("mustache");
|
|
|
|
console.log('downloading tilde.town homepage...');
|
|
|
|
axios.get('http://tilde.town/').then(function (response) {
|
|
if (response.status != 200) {
|
|
console.log('Chyba!');
|
|
return 0;
|
|
}
|
|
|
|
|
|
let userRegex = /<a href="\/~(\w+)">[\w]+<\/a>/g;
|
|
var users = Array.from(response.data.matchAll(userRegex), function (result) {
|
|
return result[1];
|
|
});
|
|
|
|
// 150 last active users
|
|
users = users.slice(0,150);
|
|
|
|
console.log('writing index.html...');
|
|
|
|
var datum = new Date();
|
|
|
|
fs.writeFileSync('index.html', mustache.render(fs.readFileSync('index.tpl.html').toString(), {
|
|
users: users,
|
|
date: datum
|
|
}));
|
|
|
|
console.log(users.length + ' users at all');
|
|
console.log('');
|
|
console.log('now let\'s download them:');
|
|
|
|
let offset = 0;
|
|
users.map(user => {
|
|
setTimeout(() => {
|
|
(async () => {
|
|
console.log('downloading ' + user + '...');
|
|
await captureWebsite.file('http://tilde.town/~'+user+'/', user+'.png', {
|
|
scaleFactor: 0.5,
|
|
overwrite: true,
|
|
timeout: 5
|
|
});
|
|
})();
|
|
}, 10000 + offset);
|
|
offset += 10000;
|
|
});
|
|
|
|
//console.log('ALL OK');
|
|
});
|
|
|
|
// captureWebsite.file('https://sindresorhus.com', 'screenshot.png', {});
|
|
|
|
// console.log("OK")
|