Wikidata:Requests for permissions/Bot/William Avery Bot 5
- The following discussion is closed. Please do not modify it. Subsequent comments should be made in a new section. A summary of the conclusions reached follows.
- Approved --Lymantria (talk) 06:14, 15 June 2022 (UTC)[reply]
William Avery Bot (talk • contribs • new items • new lexemes • SUL • Block log • User rights log • User rights • xtools)
Operator: William Avery (talk • contribs • logs)
Task/s: References to facts stated in The Database of Victims of the Nazi Persecution (Q104074149) that use reference URL (P854) will be changed to to use Holocaust.cz person ID (P9109), as requested at Wikidata:Bot requests#reference URL (P854) → Holocaust.cz person ID (P9109) (2021-02-05)
Code: https://bitbucket.org/WilliamAvery/wikipythonics/src/master/urlRefToID.py
Function details:
This is a pywikibot script, which will use the following SPARQL as a generator.
SELECT DISTINCT ?item ?id WHERE {
?item ?prop ?claim.
?claim prov:wasDerivedFrom [ pr:P248 wd:Q104074149 ; pr:P854 ?url ]
}
Each item returned is processed by the treat_page() method of the pywikibot bot class
- For each property present
- For each claim present on the property
- For each reference on the claim with stated in (P248) set to The Database of Victims of the Nazi Persecution (Q104074149)
- Stop processing the reference if reference URL (P854) is not present as a claim in the reference
- Stop processing the reference if Holocaust.cz person ID (P9109) is not present as a substantive claim on the item
- Derive the value a value for P9109 from the value of P854 by removing non-numeric characters
- If the derived value doesn't match the value for P9109 on the item
- Output a warning and stop processing the reference
- If no P9109 claim is present in the reference
- Add a new P9109 claim to the reference using the derived id
- If the reference now has a P9109 claim with value corresponding to the P854 ref_url on the reference
- Remove the P854 ref_url claim
- Else
- Warn that an id was already present on the reference that did not correspond to the ref_url
- For each reference on the claim with stated in (P248) set to The Database of Victims of the Nazi Persecution (Q104074149)
- For each claim present on the property
- If item has been changed
- Update the item
--William Avery (talk) 13:14, 2 June 2022 (UTC)[reply]
Can you do a test run? --Lymantria (talk) 07:46, 7 June 2022 (UTC)[reply]
Test runs totalling 50 items complete. The script is behaving as expected. William Avery (talk) 09:03, 8 June 2022 (UTC)[reply]
- That works great. Thanks. Daniel Baránek (talk) 10:33, 8 June 2022 (UTC)[reply]
- Support --Epìdosis 16:06, 13 June 2022 (UTC)[reply]