const { load } = require("@alex.garcia/observable-prerender"); const { Cluster } = require("puppeteer-cluster"); const fs = require("fs"); const outputFolder = 'emojis' const howManyArts = 20 const maxConcurrency = 5 const notebookId = "@codingwithfire/emojis" const cells = [ "colorTreemap", "chosen", "sortedEmojis", ] async function main() { try { fs.mkdirSync(outputFolder) } catch(e) {} const cluster = await Cluster.launch({ concurrency: Cluster.CONCURRENCY_CONTEXT, maxConcurrency, }); await cluster.task(async (params) => { page = params.page let id = params.data.notebook let i = params.data.index console.log("working on ", id, i, params.data) const notebook = await load(id, cells, { page }); // await notebook.redefine("ticks", i); const sorted = await notebook.value("sortedEmojis"); console.log("emoji", i, sorted[i]) await notebook.redefine("chosen", sorted[i]); const chosen = await notebook.value("chosen"); console.log("new chosen", chosen) let filename = `${outputFolder}/${emoji}-treemap.png` let filenameSVG = `${outputFolder}/${emoji}-treemap.svg` console.log("filename", filename) await notebook.screenshot("colorTreemap", filename); await notebook.svg("colorTreemap", filenameSVG); console.log("saved", i) // await notebook.screenshot("chart", `${notebookId}.png`.replace("/", "_")); }); let arts = Array.from({length:howManyArts}).map((d,i) => i) for await (let i of arts) { cluster.queue({ notebook: notebookId, index: i, }); } await cluster.idle(); console.log(`ffmpeg -framerate 24 -i ${outputFolder}/screenshot-%03d.png -c:v libx264 -pix_fmt yuv420p ${outputFolder}.mp4; `) await cluster.close(); console.log("exit") process.exit() } main();