User:AllyUnion/cricket code


 * 1) -*- coding: utf-8 -*-
 * 2) Written by Jason Y. Lee
 * 3) Copyright under GPL, GFDL, Creative Commons Attribution-ShareLike 1.0, 2.0, 2.5 licenses

import wikipedia, config import re

def stripafd(text): message1 = '' message2 = '' pos1 = text.find(message1) pos2 = text.find(message2) if (pos1 != -1) and (pos2 != -1): return text[0:pos1] + text[pos2+len(message2)+1:] return text
 * 1) This function strips the afd notification text, if it exists.

def crickettitle(str): if str.find(':2005 English cricket season/') == 0: return str[29:] return str

if __name__ == "__main__": Rlink = re.compile(r'\{\{(?P [^\}\|]*)(\|[^\}]*)?\}\}') site = wikipedia.getSite

tpage = wikipedia.Page(site, 'Template:2005 English cricket season chronology') pages = tpage.linkedPages for page in pages: if page.title.find('2005 English cricket season (') != -1:			text = page.get

result = [] for match in Rlink.finditer(text): found = match.group('title') if found.find(':2005 English cricket season/') != -1: result.append(found)

for item in result: # Where the text is now page1 = wikipedia.Page(site, crickettitle(item))

# The old subpage where it use to be at - this redirect should be deleted. page2 = wikipedia.Page(site, item[1:])

sub1 = u'' % item sub2 = wikipedia.removeCategoryLinks(stripafd(page1.get), site)

# Merge the text into the main article text = text.replace(sub1, sub2)

# Redirect page to main article page1.put('#REDIRECT %s' % page.aslink, 'Merging contents into main article')

# Fix double redirect - might be more appropriate to delete the redirecting subpage? page2.put('#REDIRECT %s' % page.aslink, 'Fixing double redirect')

page.put(text, 'Merging text from former subpages, per AFD discussion.')