Thanks for taking the time to respond, appreciated but unfortunatey it still does not work for me
import pywikibot wd = pywikibot.Site('wikidata', 'wikidata') repo = wd.data_repository() item = pywikibot.ItemPage(repo, 'Q42') item.get()
which I believe is the same code that works for you! but when I run it in my Jupyter notebook I get the following error (end of email)
Confused :) will explore further, I must be doing something really stupid, wouldn't be the first time!
Clemo
EntityTypeUnknownException Traceback (most recent call last) <ipython-input-444-5b9dee68bfbb> in <module> 2 wd = pywikibot.Site('wikidata', 'wikidata') 3 repo = wd.data_repository() ----> 4 item = pywikibot.ItemPage(repo, 'Q42') 5 item.get()
~/opt/anaconda3/lib/python3.7/site-packages/pywikibot/page/__init__.py in __init__(self, site, title, ns) 4674 """ 4675 if ns is None: -> 4676 ns = site.item_namespace 4677 # Special case for empty item. 4678 if title is None or title == '-1':
~/opt/anaconda3/lib/python3.7/site-packages/pywikibot/site/__init__.py in item_namespace(self) 7742 """ 7743 if self._item_namespace is None: -> 7744 self._item_namespace = self.get_namespace_for_entity_type('item') 7745 return self._item_namespace 7746
~/opt/anaconda3/lib/python3.7/site-packages/pywikibot/site/__init__.py in get_namespace_for_entity_type(self, entity_type) 7731 raise EntityTypeUnknownException( 7732 '{0!r} does not support entity type "{1}"' -> 7733 .format(self, entity_type)) 7734 7735 @property
EntityTypeUnknownException: DataSite("wikidata", "wikidata") does not support entity type "item"
________________________________________ From: pywikibot [pywikibot-bounces@lists.wikimedia.org] on behalf of AntiCompositeNumber [anticompositenumber@gmail.com] Sent: Saturday, June 27, 2020 5:23 PM To: Pywikibot discussion list Subject: Re: [pywikibot] Using the Q number to get a wikidata page
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 Paul.Clements@bl.uk 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 postmaster@bl.uk : 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 pywikibot@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot
_______________________________________________ pywikibot mailing list pywikibot@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot