Skip to content

Instantly share code, notes, and snippets.

@k-nut
Last active December 3, 2016 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-nut/81fbbfb167ec6003b534379ccdaf33bb to your computer and use it in GitHub Desktop.
Save k-nut/81fbbfb167ec6003b534379ccdaf33bb to your computer and use it in GitHub Desktop.
Add a Politician to the 16th Landtag in NRW
# -*- coding: utf-8 -*-
import pywikibot
import json
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
def mark_as_part_of_current_landtag(politican_item_id):
item = pywikibot.ItemPage(repo, politican_item_id)
claims = item.get()['claims']['P39']
legislaturperiode = u'P2937'
landtag_period = u"Q27949540" # 16th NRW
# Q17781726 is: Mitglied des Lantags Nordrhein-Westfahlen
landtag_membership = next(claim for claim in claims if claim.target.id == 'Q17781726')
qualifier = pywikibot.Claim(repo, legislaturperiode)
target = pywikibot.ItemPage(repo, landtag_period)
qualifier.setTarget(target)
landtag_membership.addQualifier(qualifier)
item.editEntity(summary='pyWikibot politican in Wahlperiode')
mark_as_part_of_current_landtag(u"Q1322650")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment