Wikidata:Requests for permissions/Bot/RarBot
The following discussion is closed. Please do not modify it. Subsequent comments should be made in a new section. A summary of the conclusions reached follows.
- Approved--Ymblanter (talk) 20:19, 30 July 2018 (UTC)[reply]
RarBot edit
RarBot (talk • contribs • new items • new lexemes • SUL • Block log • User rights log • User rights • xtools)
Operator: Rar (talk • contribs • logs)
Task/s: Adding Ukrainian sitelink (optionally description/label) for bot-created pages on uk: wiki.
Code: to simple to put on online repository, it is here:Extended content |
---|
# -*- coding: utf-8 -*- import pywikibot def add_uk_sitelink(en_uk, based_on='en', description=False, label=False): site = pywikibot.Site(based_on, 'wikipedia') page = pywikibot.Page(site, en_uk[0]) # Sitelink if page.isRedirectPage(): page = page.getRedirectTarget() try: item = pywikibot.ItemPage.fromPage(page) except: print ">>> Error - no wikidata for "+en_uk[0] return False item = pywikibot.ItemPage.fromPage(page) try: item.setSitelink(sitelink={'site': 'ukwiki', 'title': en_uk[1]}, summary=u'uk: sitelink') except: print ">>> Error - can't set sitelink for "+en_uk[0] return False # Description & Label item_dict = item.get() if description and (not "uk" in item_dict["descriptions"].keys()): item.editDescriptions({"uk": description}, summary="uk: description") if label and (not "uk" in item_dict["labels"].keys()): item.editLabels({"uk": label}, summary="uk: label") print en_uk[0]+" done" return True en_uk_list = [ # list of [en_title, uk_title] pairs [u"2014 Brisbane International – Women's Singles", u"Brisbane International 2014, жінки, одиночний розряд"] # etc. ] def main(): for en_uk in en_uk_list: add_uk_sitelink(en_uk, description=u"тенісний турнір", label=en_uk[1]) if __name__ == "__main__": try: main() finally: pywikibot.stopme() |
Function details: Bot creates semi-automatically translated pages on uk: wikipedia (as for now about tennis tournaments) and I want it can put sitelink, description, label on wikidata automatically also.
Based on pywikibot framework. Sets uk: sitelink only if it is absent. Optionally can set description and label (if corresponding function parameters are provided). It can be used also at the request of trusted users in the future.
I'm ready to make test editing on list of pages from uk:Користувач:RarBot/Tennis.
--Rar (talk) 09:55, 26 July 2018 (UTC)[reply]
- Please indeed make about 50 test edits.--Ymblanter (talk) 18:56, 26 July 2018 (UTC)[reply]
- Test run: [1]. Sitelink, description and label are added, about 60 pages.--Rar (talk) 04:44, 27 July 2018 (UTC)[reply]
- One more run: [2], 26 pages.--Rar (talk) 07:49, 28 July 2018 (UTC)[reply]
- @Ymblanter: Could you please check my bot's edits and make a decision. Sorry for hurry, but a lot of work is waiting :). --Rar (talk) 16:30, 30 July 2018 (UTC)[reply]
- One more run: [2], 26 pages.--Rar (talk) 07:49, 28 July 2018 (UTC)[reply]
- Test run: [1]. Sitelink, description and label are added, about 60 pages.--Rar (talk) 04:44, 27 July 2018 (UTC)[reply]