Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on May 19, 2019

  1. Add wikibase, wikibase_item, entities and claims.

    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`
    PierreSelim committed May 19, 2019
    Configuration menu
    Copy the full SHA
    898fa0b View commit details
    Browse the repository at this point in the history