kanasimi / wikiapi

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

README.md `page_data.wikitext` working ? #12

Closed hugolpz closed 3 years ago

hugolpz commented 3 years ago

You may want to check page_data.wikitext in your readme.md, which is not aligned with your data structure.

console.log(pagedata)
pagedata {
  pageid: 438578,
  ns: 3,
  title: 'User talk:Dragons Bot',
  revisions: [
    {
      revid: 464938,
      parentid: 464937,
      timestamp: '2021-03-01T22:36:55Z',
      contentformat: 'text/x-wiki',
      contentmodel: 'wikitext',
      '*': 'undefined\n' +
        '2\n' +
        "Hi, I'm Dragons Bot ! I plan to upload lists and others maintenances."
    }
  ],
  convert_from: 'User_talk:Dragons_Bot',
  original_title: 'User_talk:Dragons_Bot',
  is_Flow: false
}

My code

const Wikiapi = require('wikiapi');
const fetch = require("node-fetch");

 var newContent = `\nHi, I'm Dragons Bot ! I plan to upload lists and others maintenances.`;

/* (async () => {
    const url1 = 'https://raw.githubusercontent.com/lingua-libre/unilex/master/data/frequency/ig.txt'
    const response = await fetch(url1);
    const data = await response.text();
    console.log('Fetch: Done.');
})(); */

// edit page: method 2
(async () => {
    const targetWiki = new Wikiapi;
    await targetWiki.login('user', 'pass', 'en');

    await targetWiki.edit_page('Wikipedia:Sandbox', function(page_data) {
        console.log('pagedata',page_data)
        console.log('wikitext',page_data.revisions[0]['*'])
        return page_data.revisions[0]['*']                                 // <------- `return page_data.wikitext` from your readme.md but actually undefined
            + '\n2'+newContent;
    }, {bot: 1, nocreate: 1, minor: 1});
    console.log('Edit: Done.');

})();