aboutsummaryrefslogtreecommitdiff
path: root/backup/index.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-03-18 01:49:50 +0300
committerGravatar Vitaly Takmazov2023-06-14 06:16:56 +0300
commit4fe675b24dfdcb8eba2b8d03f573faaaa50b3bdb (patch)
tree28e58d5bae44cd95fec79faed6c582f273608729 /backup/index.js
parentbaae026df3007e5892541acb3f555c5a79c24500 (diff)
[backup] 2023 update: modernize code
* Yarn -> NPM * node:url -> WHATWG URL API * lodash/each -> Array.forEach * node-fetch -> Node 18 Fetch API
Diffstat (limited to 'backup/index.js')
-rw-r--r--backup/index.js15
1 files changed, 6 insertions, 9 deletions
diff --git a/backup/index.js b/backup/index.js
index 049c5bb9..fccc4439 100644
--- a/backup/index.js
+++ b/backup/index.js
@@ -1,26 +1,23 @@
var argv = require('minimist')(process.argv.slice(2));
-var fetch = require('node-fetch');
-var _ = require('lodash');
-var url = require('url');
if (typeof argv.u !== "string") {
console.log("username must be specified (-u ugnich)");
- return;
+ process.exit(1);
}
var messages = [];
function getBlogData(blogUrl, callback) {
- fetch(url.format(blogUrl))
+ fetch(blogUrl)
.then(function(res) {
return res.json()
})
.then(function(msgs) {
- _.each(msgs, function(message) {
+ msgs.forEach(function(message) {
messages.push(message);
});
if (msgs.length == 20) {
- blog.query.before_mid = msgs.slice(-1).pop().mid;
+ blog.searchParams.set("before_mid", msgs.slice(-1).pop().mid);
setTimeout(getBlogData, 1000, blog, callback);
} else {
callback();
@@ -28,8 +25,8 @@ function getBlogData(blogUrl, callback) {
});
};
-var blog = url.parse("https://api.juick.com/messages", true);
-blog.query.uname = argv.u;
+var blog = new URL("https://api.juick.com/messages");
+blog.searchParams.append("uname", argv.u);
getBlogData(blog, function() {
console.log(JSON.stringify(messages));