User:AllyUnion/cricket code

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

import wikipedia, config
import re

# This function strips the afd notification text, if it exists.
def stripafd(text):
	message1 = '<!-- Please do not remove or change this AfD message until the issue is settled -->'
	message2 = '<!-- End of AfD message, feel free to edit beyond this point -->'
	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

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

if __name__ == "__main__":
	Rlink = re.compile(r'\{\{(?P<title>[^\}\|]*)(\|[^\}]*)?\}\}')
	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'{{%s}}' % 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.')

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.