User:EditCountBot/Code

  1. Completes a template containing the editcount of a user,
  2. so it can then be used by other templates/userboxes that
  3. take the edit count of a user as a parameter.
  1. Sandbox for testing, not a complete bot

import wikipedia, userlib, re

site = wikipedia.getSite()

templateLocation = 'User:EditCountBot/Counter'

for page in wikipedia.Page(site, templateLocation).getReferences(follow_redirects=False,onlyTemplateInclusion=True):

text = page.get()

for username in re.findall(r'\{\{.*?user=(.*?)\|.*?\}\}', text, re.I):

user = userlib.User(site, username)

editCount = str(user.editCount())

newTemplate = '{{' + templateLocation + '|user=' + username + '|count=' + editCount + '}}'

text = re.sub(r'\{\{User:EditCountBot/Counter\|.*?user=EdoDodo.*?\}\}', newTemplate, text)

wikipedia.showDiff(page.get(), text)