Protoball:Add Years to Games Tab.py
Jump to navigation
Jump to search
def add_years_to_game_tabs(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")