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()`: `session.to_namespace('Category Name', 'Category')` needed #56

Closed hugolpz closed 2 years ago

hugolpz commented 2 years ago

Given core script.js :

const Wikiapi= require('wikiapi');

(async () => {
    var targetwiki = new Wikiapi('commons');
    try {
    //    await targetwiki.download(targetwiki.to_namespace('Lingua_Libre_pronunciation-cmn', 'Category'), { directory: './downloads',max_threads: 4 });
    await targetwiki.download(
        'Lingua_Libre_pronunciation-cmn',
        {
            directory: './',
            max_threads: 4,
            page_filter(page_data) {
                console.log('@Yug: ',JSON.stringify(page_data))
                return true;
            }
        });
    } catch (error) { console.log(`Download error : ${JSON.stringify(error)}`) }

})();

It failed to download, and simply returned :

yug@yug-k401ub:~/Documents/WikiapiJS-Eggs$ node ./wiki-download-many-category_tree_and_files.js
get_API_parameters: Cache commonswiki: path=query+siteinfo
get_API_parameters: Cache commonswiki: path=query+imageinfo

(Also, I don't understand the role of page_filter() so i neutralised it)

hugolpz commented 2 years ago

Actual solution, add Category: to the Category's name :

  await targetwiki.download("Category:Lingua_Libre_pronunciation-cmn",  { /* same options here */ } );

Also, allow me to facepalm myself.