kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
47 stars 5 forks source link

download is not a function #48

Closed hugolpz closed 2 years ago

hugolpz commented 2 years ago

Hello Kanasimi, Hope you are going well. Given a Commons category name, I want to download all its (12) files.

I updated wikiapi :

npm update
npm view wikiapi
wikiapi@1.19.1 | BSD-3-Clause | deps: 1 | versions: 32
...

Following the quite elegant doc, I "coded" the following:

// PURPOSE: Script to upload targets using an external data file.
// Run: $node wiki-upload-many.js
const Wikiapi= require('wikiapi');
const logins = require('./logins.js');

// Login credentials from .login*.js
var USER = logins.commons.user,
    PASS = logins.commons.pass,
    API  = logins.commons.api;

(async () => {
    // Connect
    var targetwiki = new Wikiapi;
    await targetwiki.login(USER, PASS, API);
    console.log(`Username ${USER.split('@')[0]} is connected !`);

/* *************************************************************** */
/* CORE ACTION(S) HERE : HACK ME ! ******************************* * /
    // List of targets
    const list = await targetwiki.categorymembers(`Category:Lingua Libre pronunciation by Bile rene`, { namespace: 'File' });
    // Loop on targets & save
    for(i=0;i<list.length;i++){// Set pages titles (current and new), reason and revertReason :
        page_data = list[i];
        try {
            await targetwiki.download(page_data.title, { directory: './downloads' });
        } catch (error) { console.log(`Download error on ${page_data.title} : ${error}`) }
    }

*/
    // Download all files from a (Commons) category
for (const page_data of await targetwiki.categorymembers(`Category:Lingua Libre pronunciation by Bile rene`, { namespace: 'File' })) {
    try {
        //if (targetwiki.is_namespace(page_data, 'File'))
        const file_data = await targetwiki.download(page_data.title, { directory: './downloads' });
    } catch (error) { console.log(`Download error on ${page_data.title} : ${error}`) }
}
/* END CORE ****************************************************** */
/* *************************************************************** */

})();

I get the following error message:

/WikiapiJS-Eggs$ node wiki-download-many.js 
get_API_parameters: Set commonswiki: path=query+siteinfo
Username ShufaBot is connected !
Download error on File:LL-Q33093 (bas)-Bile rene-Bonjour.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-Bonjour.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q33093 (bas)-Bile rene-Bonne nuit.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-Bonne nuit.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q33093 (bas)-Bile rene-C'est comment?.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-C'est comment?.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q33093 (bas)-Bile rene-Comment vas-tu?.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-Comment vas-tu?.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-guten tag.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-Kal nga'a?(Comment allez-vous?).wav : TypeError: wiki.download is not a function
Download error on File:LL-Q33093 (bas)-Bile rene-Que se passe t-il?.wav : TypeError: wiki.download is not a function
Download error on File:LL-Q56668 (mcn)-Bile rene-Que se passe t-il?.wav : TypeError: wiki.download is not a function

Given JSdoc3 generates the documentation from the code, and I do find download at line 1781 in both your github and my local file... I'am quite confused. Any idea ?

kanasimi commented 2 years ago

Well, I need full codes to debug...

hugolpz commented 2 years ago

Done, added above. There isn't much more really. It connects well, gets the category, gets the list of files, visibly reads the titles as expected, but doesn't recognize .download. I suspected my dependencies are broken or outdated, but I checked everywhere locally (.//node_modules/wikiapi/wikiapi.js line 1781, 1411-1425) and all seems as expected. The function download/Wikiapi_download is there and spelling is correct.

I think it's related to wikiapi.js#1414.

kanasimi commented 2 years ago

I just release cejs v4.4.2. Maybe this will solve this problem?

hugolpz commented 2 years ago

Working !

yug@yug-k401ub:~/Documents/WikiapiJS-Eggs$ node wiki-download-many.js
get_API_parameters: Cache commonswiki: path=query+siteinfo
Username ShufaBot is connected !
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q33093_(bas)-Bile_rene-Bonjour.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-Bonjour.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q33093_(bas)-Bile_rene-Bonne_nuit.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-Bonne_nuit.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q33093_(bas)-Bile_rene-C'est_comment?.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-C'est_comment?.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q33093_(bas)-Bile_rene-Comment_vas-tu?.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-Comment_vas-tu?.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-guten_tag.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-Kal_nga'a?(Comment_allez-vous?).wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q33093_(bas)-Bile_rene-Que_se_passe_t-il?.wav].
get_URL_cache_node.cache: Write data to cache file [./downloads/LL-Q56668_(mcn)-Bile_rene-Que_se_passe_t-il?.wav].

A second run do not re-download.

Seems good.