-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload.js
54 lines (46 loc) · 1.46 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const Bot = require("nodemw"),
client = new Bot({
protocol: "https",
server: "commons.wikimedia.org",
path: "/w",
debug: false,
username: process.env.WIKI_USERNAME,
password: process.env.WIKI_PASSWORD,
userAgent: "DataUSA Uploader (https://datausa.io; [email protected])"
}),
fs = require("fs");
let total;
function upload(files) {
const fileName = files.pop();
process.stdout.write(`\nUploaded ${total - files.length} of ${total}`);
const {title} = require(fileName.replace("svg", "js"));
fs.readFile(fileName, "utf8", (err, svg) => {
if (err) throw err;
fs.readFile(fileName.replace("svg", "txt"), "utf8", (err, txt) => {
if (err) throw err;
client.upload(title, svg, "updates SVG", () => {
client.edit(`File:${title}.svg`, txt, "updates description", err => {
if (err) throw err;
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(title);
if (files.length) {
setTimeout(() => upload(files), 7500);
}
else console.log("done!");
});
});
});
});
}
client.logIn(err => {
if (err) throw err;
fs.readdir("./exports", (err, files) => {
if (err) throw err;
files = files.filter(file => file.includes(".svg"))
.sort((a, b) => b.localeCompare(a))
.map(file => `./exports/${file}`);
total = files.length;
upload(files);
});
});