From 7dbd846c0df24d2ed45103d674d5ef361e6f23b3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 14 Jun 2023 06:25:28 +0300 Subject: backup: moved to `scripts` directory, cleanup lint warnings --- contrib/scripts/backup.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 contrib/scripts/backup.js (limited to 'contrib') diff --git a/contrib/scripts/backup.js b/contrib/scripts/backup.js new file mode 100644 index 00000000..8c87b2dd --- /dev/null +++ b/contrib/scripts/backup.js @@ -0,0 +1,35 @@ +var argv = require('minimist')(process.argv.slice(2)) + +if (typeof argv.u !== 'string') { + console.log('username must be specified (-u ugnich)') + process.exit(1) +} + +var messages = [] + +function getBlogData(blogUrl, callback) { + fetch(blogUrl) + .then(function(res) { + return res.json() + }) + .then(function(msgs) { + msgs.forEach(function(message) { + messages.push(message) + }) + if (msgs.length == 20) { + blog.searchParams.set('before_mid', msgs.slice(-1).pop().mid) + setTimeout(getBlogData, 1000, blog, callback) + } else { + callback() + } + }) + .catch(console.error) +} + +var blog = new URL('https://api.juick.com/messages') +blog.searchParams.append('uname', argv.u) + +getBlogData(blog, function() { + console.log(JSON.stringify(messages)) +}) + -- cgit v1.2.3