There is a section in
https://www.mediawiki.org/wiki/Manual:Pywikipediabot/Wikidata#Changing_claim...
about how to add a claim to wikidata. I was looking for ways to add claim and claim’s source as is encouraged by wikidata community. I looked through source code and there seem to be no support for sources either. That is why the message about support of “claims and sources” in rewrite branch sounded promising.
Jarek T.
User:Jarekt
From: ladsgroup@gmail.com [mailto:ladsgroup@gmail.com] Sent: Sunday, March 10, 2013 3:04 AM To: Tuszynski, Jaroslaw W.; Pywikipedia discussion list Subject: Re:Re: [Pywikipedia-l] Wikidata implementation in rewrite branch
you can see manual in mw:Pywikipediabot/Wikidata
I have never worked with rewrite branch. Any chance someone could add support of claims with sources to the main branch?
Jarek T.
User:Jarekt
From: pywikipedia-l-bounces@lists.wikimedia.org [mailto:pywikipedia-l-bounces@lists.wikimedia.org] On Behalf Of legoktm Sent: Wednesday, March 06, 2013 8:47 AM To: WikiMedia Mailing Lists Subject: [Pywikipedia-l] Wikidata implementation in rewrite branch
I just commited r11182[1] into rewrite branch, providing real Wikidata support, including claims and sources.
An example of how to use it:
site = pywikibot.Site('en','wikipedia') page = pywikibot.Page(site, 'Douglas Adams') item = pywikibot.ItemPage.fromPage(page) data = item.get() item.labels['en']
u'Douglas Adams'
item.claims
{u'p18': [Claim(Property:P18)], u'p19': [Claim(Property:P19)], u'p107': [Claim(Property:P107)], u'p31': [Claim(Property:P31)], u'p21': [Claim(Property:P21)]}
item.claims['p107'][0].sources
[Claim(Property:P143)]
item.claims['p107'][0].sources[0].target
ItemPage(Q169514)
Currently only read access is supported, I should have the write methods ready in a few days. When getting sitelinks (item.sitelinks['enwiki']), you need to provide the site.dbName() rather than a standard site object due to issues with locked wikis (see my previous mail[2]).
One thing I was wondering about, should this be split into a separate file? pywikibot/wikibase.py? These are extension specific classes not-likely to be used by many wikis and will add a lot to page.py.
I'll update the onwiki documentation[3] soon as well.
[1] https://www.mediawiki.org/wiki/Special:Code/pywikipedia/11182 [2] http://lists.wikimedia.org/pipermail/pywikipedia-l/2013-March/007766.html [3] https://www.mediawiki.org/wiki/Manual:Pywikipediabot/Wikidata
Thanks,
-- Legoktm
pywikipedia-l@lists.wikimedia.org