User:JimTittsler/CopyPagesExample


 * 1) !/usr/bin/python

import mwclient
 * 1) copy a page and its subpages

user = 'JimTittslerBot' password = 'plugh'

source = 'OLPC Tuvalu' destination = 'OLPC Kosrae' source_template = '' destination_template = '' source_redirect = '#REDIRECT [[OLPC Tuvalu' destination_redirect = '#REDIRECT [[OLPC Kosrae' summary_message = 'started from corresponding OLPC Tuvalu page'

site = mwclient.Site('WikiEducator.org', path='/') site.login(user, password)

def process_page(text): """ alter or delete wikitext during copy""" text = text.replace(source_template, destination_template) text = text.replace(source_redirect, destination_redirect) return text

for page in site.allpages(prefix=source): newpage_name = page.name.replace(source, destination) print page.name,'=>',newpage_name text = page.edit(readonly=True)

newpage = site.Pages[newpage_name] #newtext = newpage.edit newpage.save(process_page(text), summary=summary_message)