forked from vrandezo/lexicographic_coverage
-
Notifications
You must be signed in to change notification settings - Fork 3
/
update-wiki.js
44 lines (33 loc) · 1.14 KB
/
update-wiki.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
const fs = require('fs');
const MWBot = require('mwbot');
const config = JSON.parse(fs.readFileSync("config.json", "utf8"));
const langdata = JSON.parse(fs.readFileSync("language-data.json", "utf8"));
languages = Object.keys(langdata);
async function main() {
let args = process.argv.slice(2);
if (!args.length) {
console.log("Updating all languages...");
args = languages;
}
const bot = new MWBot({ apiUrl: config.api });
await bot.loginGetEditToken({
username: config.username,
password: config.password
});
for (let lang of args) {
console.log("Updating " + lang);
fs.readFile("output/missing-"+lang+".txt", "utf8", function (err, data) {
if (err)
return console.log(err);
return bot.edit("Wikidata:Lexicographical coverage/"+lang+"/Missing", data, "update list");
});
await new Promise(r => setTimeout(r, 5000));
fs.readFile("output/stats-"+lang+".txt", "utf8", function (err, data) {
if (err)
return console.log(err);
return bot.edit("Wikidata:Lexicographical coverage/"+lang+"/Statistics", data, "update statistics");
});
await new Promise(r => setTimeout(r, 5000));
}
}
main().catch(console.error);