Ricordisamoa has uploaded a new change for review. https://gerrit.wikimedia.org/r/130811
Change subject: new DataSite.setDataPiece() function to complement .editEntity() ...................................................................... new DataSite.setDataPiece() function to complement .editEntity() + new configuration variable "wb_specific_api" to use wbsetlabel, wbsetdescription and wbsetsitelink instead of wbeditentity (when possible) based on a discussion with @FelixReimann: https://www.wikidata.org/wiki/?oldid=120993576#Consecutive_bot_edits Change-Id: I2dc8c99412d40de0887cf2cf2c24696c6b65d532 --- M pywikibot/config2.py M pywikibot/page.py M pywikibot/site.py 3 files changed, 37 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/11/130811/1 diff --git a/pywikibot/config2.py b/pywikibot/config2.py index d83009d..4850ffb 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -570,6 +570,13 @@ cosmetic_changes_deny_script = ['category_redirect', 'cosmetic_changes', 'touch'] +############## WIKIBASE SETTINGS ############## +# If wb_specific_api is True, the framework tries to use specific API modules +# such as 'wbsetlabel', 'wbsetdescription' and 'wbsetsitelink' when possible, +# instead of the generic 'wbeditentity'. +# This generally triggers a more appropriate autocomment on the server. +wb_specific_api = True + ############## REPLICATION BOT ################ # You can add replicate_replace to your user_config.py, which has the following # format: @@ -606,7 +613,7 @@ # Set simulate to True or use -simulate option to block all actions given above. simulate = False -# How many pages should be put to a queue in asynchroneous mode. +# How many pages should be put to a queue in asynchronous mode. # If maxsize is <= 0, the queue size is infinite. # Increasing this value will increase memory space but could speed up # processing. As higher this value this effect will decrease. diff --git a/pywikibot/page.py b/pywikibot/page.py index 25e9046..22fa92c 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2776,7 +2776,7 @@ @type claims: list """ - # this check allows single claims to be remove by pushing them into a + # this check allows single claims to be removed by pushing them into a # list of length one. if isinstance(claims, pywikibot.Claim): claims = [claims] diff --git a/pywikibot/site.py b/pywikibot/site.py index c020774..7391c4c 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3490,7 +3490,7 @@ return lrgen -class DataSite (APISite): +class DataSite(APISite): def __getattr__(self, attr): """Calls to methods get_info, get_sitelinks, get_aliases, get_labels, @@ -3527,7 +3527,7 @@ @deprecated("pywikibot.WikibasePage") def get_item(self, source, **params): - """get the data for multiple Wikibase items""" + """Get the data for multiple Wikibase items""" if type(source) == int or \ isinstance(source, basestring) and source.isdigit(): ids = 'q' + str(source) @@ -3536,11 +3536,11 @@ wbdata = wbrequest.submit() assert 'success' in wbdata, \ "API wbgetentities response lacks 'success' key" - assert wbdata['success'] == 1, "API 'success' key ist not 1" + assert wbdata['success'] == 1, "API 'success' key is not 1" assert 'entities' in wbdata, \ "API wbgetentities response lacks 'entities' key" assert ids in wbdata['entities'], \ - "API wbgetentities response lacks %s key" % ids + "API wbgetentities response lacks %s key" % ids return wbdata['entities'][ids] else: # not implemented yet @@ -3622,10 +3622,17 @@ @must_be(group='user') def editEntity(self, identification, data, bot=True, **kwargs): - if "id" in identification and identification["id"] == "-1": - del identification["id"] + if 'id' in identification and identification['id'] == '-1': + del identification['id'] params = dict(**identification) - if not params: # If no identification was provided + if params: # Try to use the most appropriate API module + if len(data) == 1 and config.wb_specific_api is True: + for key, val in data.iteritems(): + if key in ['labels', 'descriptions', 'sitelinks']: + if len(val): + for k, v in val.iteritems(): + return self.setDataPiece(identification, key[:-1], v, bot=bot, **kwargs) + else: # If no identification was provided params['new'] = 'item' # TODO create properties+queries params['action'] = 'wbeditentity' if bot: @@ -3643,6 +3650,20 @@ return data @must_be(group='user') + def setDataPiece(self, identification, key, data, bot=True, **kwargs): + req = api.Request(site=self, action='wbset' + key, + token=self.token(pywikibot.Page(self, u'Main Page'), 'edit'), # Use a dummy page + **data) + req.update(identification) + if bot: + req['bot'] = 1 + for arg in ('baserevid', 'summary'): + if arg in kwargs and kwargs[arg]: + req[arg] = kwargs[arg] + data = req.submit() + return data + + @must_be(group='user') def addClaim(self, item, claim, bot=True, **kwargs): params = dict(action='wbcreateclaim', -- To view, visit https://gerrit.wikimedia.org/r/130811 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2dc8c99412d40de0887cf2cf2c24696c6b65d532 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ricordisamoa <ricordisa...@live.it> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits