gallery/bin/make_gallery.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-05-28 10:40:07 +00:00
#! /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('https://tilde.town/').then(function (response) {
let userRegex = /<a href="\/~(\w+)">[\w]+<\/a>/g;
var users = Array.from(response.data.matchAll(userRegex), function (result) {
return result[1];
});
//users = users.slice(0,15);
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
}));
2020-05-28 10:42:16 +00:00
console.log(users.length + ' users at all');
console.log('');
console.log('now let\'s download them:');
2020-05-28 10:40:07 +00:00
let offset = 0;
users.map(user => {
setTimeout(() => {
(async () => {
console.log('downloading ' + user + '...');
await captureWebsite.file('https://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")