Protoball:Add Years to Games Tab.py: Difference between revisions

From Protoball
Jump to navigation Jump to search
(Created page with "Category:Python Scripts <pre> def add_years_to_game_tabs(site, regions): def add_year(line, year): index = 100 for month in months: if month in line: index = m...")
 
No edit summary
Line 1: Line 1:
[[Category:Python Scripts]]
[[Category:Python Scripts]]
<pre>
<pre>
def add_years_to_game_tabs(site, regions):
def add_years_to_games_tab(site, regions):
def add_year(line, year):
def add_year(line, year):
index = 100
index = 100

Revision as of 14:47, 30 July 2012

def add_years_to_games_tab(site, regions):
	def add_year(line, year):
		index = 100
		for month in months:
			if month in line:
				index = min(index, line.find(month))
		line = line[0:index+3] + ", " + year + line[index+3:]
		return line
	
	months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
	next_is_date = False
	year = ""
	for region in regions:
		page = site.Pages['Game_Tab:' + region]
		text = page.edit()
		lines  = [line for line in text.split("\n")]
		for i, line in enumerate(lines):
			if line.startswith("=="):
				year = line[3:7]
			elif line.startswith("|-"):
				next_is_date = True
			elif next_is_date:
				lines[i] = add_year(line, year)
				next_is_date = False
		text = "\n".join(lines)
		page.save(text, "Add years to date fields")