const Wikiapi= require('wikiapi');
const fetch = require('node-fetch');
const fs = require('fs');
const logins = require('./logins-ShufaBot.js');
const files = require('./data/zi-reds.js'); // ls -1 *.svg > zi-reds.js
// PURPOSE: Script uploads file 丁-red.png and similar to Commons.
// Edit login credentials
var USER = logins.commons.user,
PASS = logins.commons.pass,
API = logins.commons.api;
wikicode = '';
console.log('Username:', USER);
(async () => {
// Connect
console.log('Connects');
const targetWiki = new Wikiapi;
await targetWiki.login(USER, PASS, API);
console.log('Connected!');
// upload file / media
for(i=0;i<files.length;i++){
let zi = files[i].zi;
wikicode=`{{SOlicense|${zi}||red.png||license=PD}}`;
let result = await targetWiki.upload({
file_path: `./reds/png/${zi}.png`,
comment: `Upload red stroke order for Chinese character ${zi}.`,
text: wikicode
});
}
})();
Then:
$/node ./create-Commons-upload.js
Username: ShufaBot
Connects
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: Retry 1/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: Retry 2/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: Retry 3/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: Retry 4/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: Got error when retrieving [https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1]: BAD STATUS
wiki_API_query: BAD STATUS: https://commons.wikimedia.org/api.php?assert=user&maxlag=5&format=json&utf8=1
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
get_URL_node: Retry 1/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
get_URL_node: Retry 2/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
get_URL_node: Retry 3/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
get_URL_node: Retry 4/4: BAD STATUS
get_URL_node: 異常 HTTP 狀態碼 404:https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
get_URL_node: Got error when retrieving [https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1]: BAD STATUS
wiki_API_query: BAD STATUS: https://commons.wikimedia.org/api.php?action=query&meta=tokens&type=login&maxlag=5&format=json&utf8=1
wiki_API.login: 無法 login! Abort! Response:
BAD STATUS
Then: