User:SamoaBot/Wikidata Summary

From Meta, a Wikimedia project coordination wiki

This is a new and advanced alternative to User:Addbot/Wikidata Summary. Feel free to translate the message here.

For bot-developers/operators[edit]

You can easily update your localized summary as follows:

# -*- coding: utf-8  -*-
# code by Ricordisamoa, released as CC0 — "No Rights Reserved": the Public Domain Dedication as written by Creative Commons
# requires the Pywikipediabot rewrite branch

import pywikibot

summary={}

for page in pywikibot.Site('meta','meta').allpages(namespace=1198,prefix='User:SamoaBot/Wikidata Summary/translate/1/',filterredir=False):
	text=page.get(force=True)
	text=text.replace('{{plural:','{{PLURAL:')  # to make it compatible with pywikibot.i18n
	text=text.replace('$counter','%(counter)d') # if you want to ease its use with pywikibot.i18n
	text=text.replace('$user','%(user)s')  #   same
	text=text.replace('$id','%(id)s')     # ..and same
	summary[page.title().split('/')[-1]]=text

# print...
print summary
# ...and eventually export to file
summary_file=open('wikidata_summary.py','w')
summary_file.write('summary='+str(summary))

...and then use this summary everywhere:

import pywikibot
from wikidata_summary import summary

site=pywikibot.Site('et','wikipedia')
counter=14 # number of removed interwiki links
item=pywikibot.ItemPage(pywikibot.Site('wikidata','wikidata'),'Q2001')
# the desired summary in Estonian (will fallback to English)
print pywikibot.i18n.translate(site.lang,summary,{'counter':counter,'user':site.user(),'id':item.getID()})