You should be calling pywikibot.ItemPage with the data repository, not the site.

>>> import pywikibot
>>> wd = pywikibot.Site('wikidata', 'wikidata')
>>> repo = wd.data_repository()
>>> item = pywikibot.ItemPage(repo, 'Q42')
>>> item.get()
{'labels': <pywikibot.page.LanguageDict object at 0x7f69c8ca18e0>,
'descriptions': <pywikibot.page.LanguageDict object at
0x7f69c88fc8b0>, 'aliases': <pywikibot.page.AliasesDict object at
0x7f69c88fc6d0>, 'claims': <pywikibot.page.ClaimCollection object at
0x7f69c88fca30>, 'sitelinks': <pywikibot.page.SiteLinkCollection
object at 0x7f69c88fc940>}
>>> item.claims["P31"][0].getTarget()
ItemPage('Q5')

I couldn't get pywikibot.ItemPage.fromPage to work properly, but it
looks like that is related to
<https://phabricator.wikimedia.org/T242081>.

AntiCompositeNumber

On Sat, Jun 27, 2020 at 10:55 AM Clements, Paul <[email protected]> wrote:
>
> Hi,
>
> I am trying to use a q number to get the details of a page in wikidata.  I 
> have searched through the tutorials and found these that claim to work
>
>         wikidata = pywikibot.Site("wikidata", "wikidata")
>         repo = wikidata.data_repository()
>
>         item = pywikibot.ItemPage(wikidata, 
> "Q42").get()['claims']['P31'][0].getTarget()
>         itempage = 
> pywikibot.ItemPage.fromPage(pywikibot.Page(pywikibot.Site("en", "wikipedia"), 
> "Douglas Adams"))
>
> However when I run either of these then I get the
>
> EntityTypeUnknownException: DataSite("wikidata", "wikidata") does not support 
> entity type "item"
>
>
> As I am new to this and also python I am sure I am doing something stupid but 
> its currently driving me mad.
>
> Any help would be appreciated
>
> Clemo
>
>
>
>
>
> ******************************************************************************************************************
> Experience the British Library online at www.bl.uk
> The British Library’s latest Annual Report and Accounts : 
> www.bl.uk/aboutus/annrep/index.html
> Help the British Library conserve the world's knowledge. Adopt a Book. 
> www.bl.uk/adoptabook
> The Library's St Pancras site is WiFi - enabled
> *****************************************************************************************************************
> The information contained in this e-mail is confidential and may be legally 
> privileged. It is intended for the addressee(s) only. If you are not the 
> intended recipient, please delete this e-mail and notify the [email protected] 
> : The contents of this e-mail must not be disclosed or copied without the 
> sender's consent.
> The statements and opinions expressed in this message are those of the author 
> and do not necessarily reflect those of the British Library. The British 
> Library does not take any responsibility for the views of the author.
> *****************************************************************************************************************
> Think before you print
> _______________________________________________
> pywikibot mailing list
> [email protected]
> https://lists.wikimedia.org/mailman/listinfo/pywikibot

_______________________________________________
pywikibot mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot

Reply via email to