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

Fail to remove property's value #71

Closed hugolpz closed 4 weeks ago

hugolpz commented 4 weeks ago

Hello Kanasimi,

I hope you are going well.

Some news from my side. I'm lightly back on Lingualibre cleaning. I try to update claims P3, which means remove then add.

I follow the manual https://kanasimi.github.io/wikiapi/Wikiapi.html#data

My script 1) fail to remove (does nothing, no error either), 2) succeed to add the new value. So my property ends up with 2 videos while I just wants the new one.

Also, a github search on remove seems to only shows the manual's examples, and no active code using remove. https://github.com/search?q=repo%3Akanasimi%2Fwikiapi+remove&type=code

So I wonder if the feature is active.

Reproduce bug

Givent ./data/videos.js

module.exports = [ /* commented code has already be edited in past tests on lingualibre.org */
  // { "lili": "Q100206", "wikitext":"{{Elix|word=Achat}}", "filename":"Achat_Nm_1_1_1_-_Elix.ogv" },
  // { "lili": "Q100207", "wikitext":"{{Elix|word=Alasaintglinglin}}", "filename":"Alasaintglinglin_Adv_1_1_-_Elix.ogv" },
  // { "lili": "Q100208", "wikitext":"{{Elix|word=Ame}}", "filename":"Ame_Nf_2_2_1_-_Elix.ogv" },
  // { "lili": "Q100209", "wikitext":"{{Elix|word=Analogie}}", "filename":"Analogie_Nf_1_2_1_-_Elix.ogv" },
  // { "lili": "Q100210", "wikitext":"{{Elix|word=Appetit}}", "filename":"Appetit_Nm_1_1_1_-_Elix.ogv" },
  { "lili": "Q100216", "wikitext":"{{Elix|word=Archipel}}", "filename":"Archipel_Nm_1_2_1_-_Elix.ogv" },
  { "lili": "Q100217", "wikitext":"{{Elix|word=Bapteme}}", "filename":"Bapteme_Nm_2_1_1_-_Elix.ogv" },
  { "lili": "Q100218", "wikitext":"{{Elix|word=Barbele}}", "filename":"Barbele_Adj_1_1_1_-_Elix.ogv" },
  { "lili": "Q100219", "wikitext":"{{Elix|word=Blouse}}", "filename":"Blouse_Nf_2_1_1_-_Elix.ogv" },
  { "lili": "Q100220", "wikitext":"{{Elix|word=Bobine}}", "filename":"Bobine_Nf_2_1_1_-_Elix.ogv" },
  { "lili": "Q100221", "wikitext":"{{Elix|word=Bonjour}}", "filename":"Bonjour_Nm_1_1_1_-_Elix.ogv" },
  { "lili": "Q100222", "wikitext":"{{Elix|word=Boudin}}", "filename":"Boudin_Nm_1_1_1_-_Elix.ogv" },
  { "lili": "Q100223", "wikitext":"{{Elix|word=Caducee}}", "filename":"Caducee_Nm_1_2_1_-_Elix.ogv" },
  { "lili": "Q100224", "wikitext":"{{Elix|word=Canal}}", "filename":"Canal_N_1_1_1_-_Elix.ogv" },
  { "lili": "Q100225", "wikitext":"{{Elix|word=Canicule}}", "filename":"Canicule_Nf_1_1_1_-_Elix.ogv" },
  { "lili": "Q100226", "wikitext":"{{Elix|word=Champ}}", "filename":"Champ_Nm_1_1_1_-_Elix.ogv" },
  { "lili": "Q100227", "wikitext":"{{Elix|word=Champignon}}", "filename":"Champignon_Nm_1_1_1_-_Elix.ogv" }
];

Then logins.js :

module.exports = {
    liliFull : {
        language : 'en',
        API_URL : 'https://lingualibre.org/api.php',
        data_API_URL : 'https://lingualibre.org/api.php',
        SPARQL_API_URL : 'https://lingualibre.org/bigdata/namespace/wdq/sparql',
        user_name: 'Dragons Bot@Dragons_Bot',
        password: 'mypassword',
        //origin: '*',
    }
]

Then script.js:


const Wikiapi= require('wikiapi');
var logins = require('./logins.js');
const videos = require('./data/videos.js')

// require('./wiki loader.js');

// Edit login credentials
var login_options = logins.liliFull;

(async () => {
    const targetWiki = new Wikiapi;
    await targetWiki.login(logins.liliFull); 
    for (var i=0;i<2;i++) {    //  LIMITING THE EDITS TO 2 FOR TESTING
        var currFile = videos[i].filename,
            newFile = videos[i].filename.replace(/.ogv/gi,'.webm');
        console.log('P3 edit : ', currFile,'---->',newFile)

        try{
        // update wikidata
        /* ******************************** FAILS ********************************* */
        let entity = await targetWiki.data(videos[i].lili);
        await entity.modify({ claims: [{ P3: currFile, remove: true }] }, { bot: 1, summary: 'remove P3' });

        /* ******************************** WORKS ********************************* */
        entity = await targetWiki.data(videos[i].lili);
        await entity.modify({ claims: [{ P3: newFile }] }, { bot: 1, summary: 'refill P3' });

        }catch(e){ console.error(e); }
    }

})();

See also

kanasimi commented 4 weeks ago

Maybe you can use CeL.wiki.data.value_of(entity.claims.P3)[0] instead of currFile?

hugolpz commented 4 weeks ago

Ok I see. It works (Special:Contributions/Dragons_Bot).

Indeed, the strings are slightly different : Source Type Value
Commons.wikimedia.org filename string Coq_Nm_1_11-_Elix.ogv
./data/videos.js currFile string (carefully extracted from Commons) Coq_Nm_1_11-_Elix.ogv
Lingualibre.org P3 string Coq Nm 1 1 1 - Elix.ogv

It is true wikimedia Commons has an url resolver for

"_" == " " // underscore resolves as equal to blank space.

image

P3val = CeL.wiki.data.value_of(entity.claims.P3)[0];
console.log(currFile," vs ",P3val)                    //   Coq_Nm_1_1_1_-_Elix.ogv vs Coq Nm 1 1 1 - Elix.ogv

I was locked on this one and didn't know how to print the P3's value.

Thank you @kanasimi 👍🏼