Hi pywikibot experts,
How can I create new properties via pywikibot? (I'm trying to do it via bot, because I'm doing some experiments on a dedicated wikibase installation with - possibly - hundreds of properties to be created... and Pywikibot would certainly be my favorite tool!)
Using pywikibot, I'm able to MODIFY existing properties with instructions like the following ones (which let me generate the object-content in one shot via json ... as I need):
In [1]: import pywikibot ; site = pywikibot.Site() ; repo = site.data_repository()
In [2]: property_page = pywikibot.PropertyPage(repo, u"P2")
In [3]: myjson = {u'descriptions': {u'en': {u'language': u'en', u'value': u'invented description'}}, u'labels': {u'en': {u'language': u'en', u'value': u'test property'}}}
In [4]: property_page.editEntity(myjson)
...but I cannot CREATE new properties (instantiating a PropertyPage object), because pywikibot asks for the identifier of an existing instance:
In [11]: p_page = pywikibot.PropertyPage(repo)
---------------------------------------------------------------------------
InvalidTitle Traceback (most recent call last)
<ipython-input-11-e72b812b8cd3> in <module>()
----> 1 p_page = pywikibot.PropertyPage(repo)
/home/user/src/pywikibot_repo/pywikibot/page.pyc in __init__(self, source, title)
4027 if not title or not self.id.startswith('P'):
4028 raise pywikibot.InvalidTitle(
-> 4029 u"'%s' is not an property page title" % title)
4030 Property.__init__(self, source, self.id) 4031
InvalidTitle: '' is not an property page title
In [12]:
In fact, as I understand, in the source code of the "WikibasePage" class, I see that
# Special case for empty item.
if title is None or title == '-1':
super(ItemPage, self).__init__(site, u'-1', ns=ns)
return
if not title or not self.id.startswith('P'):
raise pywikibot.InvalidTitle(
u"'%s' is not an property page title" % title)
Property.__init__(self, source, self.id)
Thanks a lot for your attention!