User:GeertivpBot/Pywikibot/Scripts/add image from sdc.py

From Meta, a Wikimedia project coordination wiki

add_image_from_sdc.py is a bot to add media files to Wikidata, based on corresponding SDC metadata in Wikimedia Commons.

Extremely easy to use. It is not overwriting existing data, and does not add images when other items already have a corresponding P18 or other media links.

Metadata[edit]

It uses SDC metadata from Wikimedia Commons to add P18, or equivalent media link statements to Wikidata items.

Based on the metadata it is decides what type of of media link is generated.

Usage[edit]

pwb add_image_from_sdc "Wikimedia category"

or

pwb add_image_from_sdc

followed by a list of Wikimedia media files, one per line in stdin

Parameters[edit]

    P1: Wikimedia category (either with _ or between "")

or

    stdin: list of media files, one per line

Algorithm[edit]

For each of the images the SDC metadata is analysed, and the best fitting Wikidata media file link is generated.

The Wikidata item number is obtained from the SDC data and/or from an Information template in the Wiki text, where the item number is obtained from its parameter. In the latter case an additional SDC depicts statement is generated in the Wikimedia Commons SDC structured data.

Code[edit]

More information about its functionality, error handling, and algorithm is available in the code header.