New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wikibase client (read only) #96
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for pushing this! I'll try to read over the code in the weekend. |
@danmichaelo do not hesitate to comment things that you don't like in my code :) |
When doing tab completion on the Site object, it's a bit confusing to have both @property
def wikibase_repo(self):
"""
Get a reference to the associated Wikibase repository site.
Returns:
a WikiBaseSite object
"""
if self._wikibase_repo is None:
result = self.api('query', meta='wikibase')
url = result['query']['wikibase']['repo']['url']
host = url['base'].replace('//', '')
path = url['scriptpath'] + "/"
self._wikibase_repo = WikiBaseSite(('https', host),
path=path,
pool=self.connection)
return self._wikibase_repo I guess |
mwclient/entity.py
Outdated
self._labels = None | ||
|
||
# caching claims | ||
self.itemclaims = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix this one with underscore as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be the logic thing to do +1 :)
As discussed in mwclient#96
.idea/dictionaries/Pierre_Selim.xml
Outdated
@@ -0,0 +1,7 @@ | |||
<component name="ProjectDictionaryState"> | |||
<dictionary name="Pierre-Selim"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please remove this file ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ashamed this got pushed ... I just rebased it ^_^
As discussed in mwclient#96 wikibase_item() and wikibase() are good candidate for properties. Typo: dictionnary -> dictionary
c038d49
to
457d7ea
Compare
As discussed in mwclient#96 wikibase_item() and wikibase() are good candidate for properties. Typo: dictionnary -> dictionary
4405c21
to
94edddb
Compare
@PierreSelim and @danmichaelo, since these things sometimes fall off our radar, I'm just pinging you in case there's something other than dev work (e.g. a comment to respond) stalling the discussion. What's the status, what needs to be done? |
@waldyrious and @danmichaelo true this has totally fell off my radar, I'll probably re-read the review and try to adress what I can this week. Still annoys me to use pywikibot when I don't need to just to get few simple wikibase API results :) |
Cool! I'll try to respond quickly if you post something. If you want to discuss anything more in detail, we could also do a Gitter chat. |
As discussed in mwclient#96 wikibase_item() and wikibase() are good candidate for properties. Typo: dictionnary -> dictionary
@danmichaelo right now I'm rebasing and squashing for readability purpose :) |
eddbdb2
to
2a773e1
Compare
Wikibase and wikibase_item(): >>> import mwclient >>> site = mwclient.Site(('https', 'fr.wikipedia.org')) >>> p = site.Pages['Nicolas Sarkozy'] >>> p.wikibase_item() <Item object Q329 (('https', u'www.wikidata.org'))> >>> site.wikibase() <WikiBaseSite object '('https', u'www.wikidata.org')/w/'> Added entities() to WikiBaseSite It works this way >>> import mwclient >>> site = mwclient.WikiBaseSite(('https', 'www.wikidata.org')) >>> ent = site.entities('Q422') >>> q422 = ent[0] >>> q422 <Item object Q422 (('https', 'www.wikidata.org'))> >>> q422.claims() Fetching labels, descriptions and sitelinks for entities >>> import mwclient >>> site = mwclient.WikiBaseSite(('https', 'www.wikidata.org')) >>> q = mwclient.entity.Item(site, 'Q42') >>> q.sitelinks >>> q.labels >>> q.descriptions ids filter for entities(): >>> import mwclient >>> wikidata = mwclient.WikiBaseSite(('https', 'www.wikidata.org')) >>> entities = wikidata.entities(ids=['Q42', 'P238']) >>> for entity in entities: >>> print entity <Property object P238 (('https', 'www.wikidata.org'))> <Item object Q42 (('https', 'www.wikidata.org'))> Property filter in claims(): >> import mwclient >> site = mwclient.Site(('https', 'en.wikipedia.org')) >> article = site.Pages['Nicolas Sarkozy'] >> item = article.wikibase_item() >> #only distinction >> for claim in item.claims(prop=['P166']): >> print claim >> # All Claims >> for claim in item.claims(): >> print claim Claim object have now both properties: * `snaktype` * `value` set to `None` if `snaktype` is either `somevalue` or `novalue`
hey again! @waldyrious looped me into helping out with maintaining mwclient since dan is inactive ATM. I'm looking through old pull requests, obviously this one is pretty large and will take a minute to get familiar with, but if you're still interested, could you look at rebasing it? One thing I'd definitely personally want to request to merge this: tests! I'd hate to merge a major new feature with no tests. Do you think you could write some? Thanks again! |
I've been working on implementation of reading method of the wikibase API:
Example of how it works: