#! /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 = /[\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 })); 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('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")