Last active
August 29, 2015 14:01
-
-
Save samuell/6e6907aa40b735624fd2 to your computer and use it in GitHub Desktop.
Query Semantic MediaWiki via MediaWiki REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [wiki] | |
| user = MyWikiBotUser | |
| pass = ******** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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