Question

Wikidata is a collection of objects that have properties.

e.g. The object Barcelona has a "coordinate location" property with value "41°22'57"N, 2°10'37"E".

Let's say the property is not set yet. How can I set it programmatically?

Was it helpful?

Solution

Using the Pywikibot compat framework:

# -*- coding: utf-8  -*-

# Set the Wikivoyage banner of a destination on Wikidata.

import pywikibot

print "Defining data source"
site = pywikibot.Site("en", "wikivoyage")
page = pywikibot.Page(site, u"Asahikawa")
data = pywikibot.DataPage(page)

print "Loading data"
dictionary = data.get()

print "Setting Wikivoyage banner"
data.editclaim(948, u"Kaguraoka Park (Asahikawa) banner.jpg")
print "Banner has been set"

Another option could be to directly use the action=wbcreateclaim part of the Wikidata API.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top