Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save samuell/6e6907aa40b735624fd2 to your computer and use it in GitHub Desktop.

Select an option

Save samuell/6e6907aa40b735624fd2 to your computer and use it in GitHub Desktop.
Query Semantic MediaWiki via MediaWiki REST API
[wiki]
user = MyWikiBotUser
pass = ********
from simplemediawiki import MediaWiki
from ConfigParser import ConfigParser
conf = ConfigParser()
conf.readfp(open('myconfig.cfg'))
w = MediaWiki('http://example.org/w/api.php')
wikiuser = conf.get('wiki', 'user')
wikipass = conf.get('wiki', 'pass')
w.login(user=wikiuser, passwd=wikipass)
jsondata = w.call({'action' : 'ask',
'q' : '[[Category:Some Category]]',
'po' : 'Some Property',
'format' : 'json',
'limit' : 100000 })
wiki_datas = jsondata['ask']['results']['items']
wiki_pages = {}
for wiki_data in wiki_datas:
title = wiki_data['title']['mTextform']
properties = wiki_data['properties']['Some Property']
wiki_pages[title] = properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment