.upload_file is not a function
hugolpz opened this issue · comments
Lopez Hugo commented
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'); // to get the list: 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({
file_path: `./reds/png/${zi}.png`,
comment: `Upload red stroke order for Chinese character ${zi}.`,
text: wikicode
});
}
})();
Then:
$ node ./create-Commons-upload.js --trace-warnings
Username: ShufaBot@ShufaBot # personal console.log
Connects
get_API_parameters: Set enwiki: path=query+siteinfo
get_API_parameters: Set commonswiki: path=query+siteinfo
Connected! # personal console.log
(node:48717) UnhandledPromiseRejectionWarning: TypeError: targetWiki.upload_file is not a function
at /home/yug/Documents/DragonsBot/create-Commons-upload.js:25:36
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:48717) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:48717) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Lopez Hugo commented
.upload_file
doesn't exist anymore due to recent edits. Doc should be changed.
Lopez Hugo commented
kanasimi commented
fixed