Hi all,
i'm working on a bot whose task is to add some SDC claims to the mediainfo of Commons file pages. While there's a method removeClaims() (see https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....) to remove multiple claims in one step, its counterpart addClaim() (see https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....) doesn't accept a list of claims to add. This results in separate API calls (?) for each single claim top add. Is there a factual reason for that difference? Is there a different way to add multiple SDC claims in one edit step?
Thanks in advance!
Florian
Hi, From reading the source code, I can't find anything that would allow it but adding a patch to make it happen shouldn't be hard. On top of that, you can introduce it in your script directly and hit the API from there. I know it's not great but it would work.
HTH
Am So., 8. Sept. 2024 um 13:34 Uhr schrieb tohuuu th@tohuuu.de:
Hi all,
i'm working on a bot whose task is to add some SDC claims to the mediainfo of Commons file pages. While there's a method removeClaims() (see
https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....)
to remove multiple claims in one step, its counterpart addClaim() (see
https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....)
doesn't accept a list of claims to add. This results in separate API calls (?) for each single claim top add. Is there a factual reason for that difference? Is there a different way to add multiple SDC claims in one edit step?
Thanks in advance!
Florian
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
Amir,
thank you for your feedback! But after checking the Wikidata API, I don't know how to get around the API limitations. PWB seems to simply call two API commands: wbremoveclaims (https://www.wikidata.org/w/api.php?action=help&modules=wbremoveclaims ) and wbsetclaim (https://www.wikidata.org/w/api.php?action=help&modules=wbsetclaim ) - so it seems that the API itself doesn't allow setting more than one claim with one command. But I've seen other bots doing multiple property changes within one edit (so I think one API call), for example https://commons.wikimedia.org/w/index.php?title=File%3AGasteinertal_vom_Zitt... so there must be a different way besides MediaInfo.addClaim().
Greetings, Florian
Am 09.09.24 um 15:24 schrieb Amir Sarabadani:
Hi, From reading the source code, I can't find anything that would allow it but adding a patch to make it happen shouldn't be hard. On top of that, you can introduce it in your script directly and hit the API from there. I know it's not great but it would work.
HTH
Am So., 8. Sept. 2024 um 13:34 Uhr schrieb tohuuu th@tohuuu.de:
Hi all, i'm working on a bot whose task is to add some SDC claims to the mediainfo of Commons file pages. While there's a method removeClaims() (see https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot.MediaInfo.removeClaims) to remove multiple claims in one step, its counterpart addClaim() (see https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot.MediaInfo.addClaim) doesn't accept a list of claims to add. This results in separate API calls (?) for each single claim top add. Is there a factual reason for that difference? Is there a different way to add multiple SDC claims in one edit step? Thanks in advance! Florian _______________________________________________ pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/message/ELXJJ4GGAJXP6JROEZPLCAGGQZBJL2W6/ To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
-- Amir (he/him)
pywikibot mailing list --pywikibot@lists.wikimedia.org Public archives athttps://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email topywikibot-leave@lists.wikimedia.org
you need to use wbeditentity or some restbase equivalent.
Am Do., 12. Sept. 2024 um 19:13 Uhr schrieb tohuuu th@tohuuu.de:
Amir,
thank you for your feedback! But after checking the Wikidata API, I don't know how to get around the API limitations. PWB seems to simply call two API commands: wbremoveclaims ( https://www.wikidata.org/w/api.php?action=help&modules=wbremoveclaims ) and wbsetclaim ( https://www.wikidata.org/w/api.php?action=help&modules=wbsetclaim ) - so it seems that the API itself doesn't allow setting more than one claim with one command. But I've seen other bots doing multiple property changes within one edit (so I think one API call), for example https://commons.wikimedia.org/w/index.php?title=File%3AGasteinertal_vom_Zitt... so there must be a different way besides MediaInfo.addClaim().
Greetings, Florian
Am 09.09.24 um 15:24 schrieb Amir Sarabadani:
Hi, From reading the source code, I can't find anything that would allow it but adding a patch to make it happen shouldn't be hard. On top of that, you can introduce it in your script directly and hit the API from there. I know it's not great but it would work.
HTH
Am So., 8. Sept. 2024 um 13:34 Uhr schrieb tohuuu th@tohuuu.de:
Hi all,
i'm working on a bot whose task is to add some SDC claims to the mediainfo of Commons file pages. While there's a method removeClaims() (see
https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....)
to remove multiple claims in one step, its counterpart addClaim() (see
https://doc.wikimedia.org/pywikibot/master/api_ref/pywikibot.html#pywikibot....)
doesn't accept a list of claims to add. This results in separate API calls (?) for each single claim top add. Is there a factual reason for that difference? Is there a different way to add multiple SDC claims in one edit step?
Thanks in advance!
Florian
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
-- Amir (he/him)
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
ah, great - thanks again - that was the "missing link"...
datarepo = pywikibot.site.DataSite('commons', 'commons') media_identifier = 'M{}'.format(page.pageid) # thanks to https://byabbe.se/2020/09/15/writing-structured-data-on-commons-with-python dict = {'id': media_identifier } datarepo.editEntity(dict, <json-payload>, summary='<my summary>')
works fine!
Am 12.09.24 um 19:58 schrieb Amir Sarabadani:
you need to use wbeditentity or some restbase equivalent.