Dear pywikibot experts,
Thanks very much: your suggestion worked perfectly, and I can create
complex Property.
In addition to the 2 options, discussed up to now ...
(
- solution via Pywikibot: which would require a new patch to the library,
as André Costa explained
https://lists.wikimedia.org/pipermail/pywikibot/2016-March/009420.html
- solution via php script "importProperties.php": as described in
https://lists.wikimedia.org/pipermail/pywikibot/2016-March/009419.html
)
... following Ricordisamoa's suggestion, I can create new COMPLEX Property
via "API wrapping", also containing Statements with Qualifier and Reference!

Here are the instructions:

import json ; import pywikibot ; site = pywikibot.Site('en', 'mywiki') ;
site.login()

data = {u'aliases': {},
 u'claims': {u'P2': [{u'mainsnak': {u'datatype': u'string',
     u'datavalue': {u'type': u'string', u'value': u'value for test
property'},
     u'property': u'P2',
     u'snaktype': u'value'},
    u'qualifiers': {u'P3': [{u'datatype': u'string',
       u'datavalue': {u'type': u'string',
        u'value': u'string target for Qualifier'},
       u'property': u'P3',
       u'snaktype': u'value'}]},
    u'qualifiers-order': [u'P3'],
    u'rank': u'normal',
    u'references': [{u'snaks': {u'P36': [{u'datatype': u'string',
         u'datavalue': {u'type': u'string',
          u'value': u'srting target for Reference'},
         u'property': u'P36',
         u'snaktype': u'value'}]},
      u'snaks-order': [u'P36']}],
    u'type': u'statement'}]},
 u'datatype': u'string',
 u'descriptions': {u'en': {u'language': u'en',
   u'value': u'invented description'}},
 u'labels': {u'en': {u'language': u'en',
   u'value': u'Complex property created via API'}},
 u'type': u'property'}

req = site._simple_request(**params) ; print(req.submit())


> Date: Fri, 25 Mar 2016 20:18:52 +0100
> From: Ricordisamoa <[email protected]>
> To: [email protected]
> Subject: Re: [pywikibot] How to create a new Property via pywikibot?
> Message-ID: <[email protected]>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Example
>
> import json
> import pywikibot
>
> site = pywikibot.Site('en', 'mywiki')
> site.login()
> data = {
>      'datatype': 'string',  # mandatory
>      'descriptions': {
>          'en': {
>              'language': 'en',
>              'value': 'invented description'
>          }
>      },
>      'labels': {
>          'en': {
>              'language': 'en',
>              'value': 'test property'
>          }
>      }
> }
> params = {
>      'action': 'wbeditentity',
>      'new': 'property',
>      'data': json.dumps(data),
>      'summary': 'my edit summary',
>      'token': site.tokens['edit']
> }
> req = site._simple_request(**params)
> print(req.submit())
_______________________________________________
pywikibot mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot

Reply via email to