import pywikibot
import sys
from difflib import context_diff
from pywikibot import pagegenerators, Timestamp
import datetime, re

site = pywikibot.Site('meta','meta')
repo = site.data_repository()
gen = pagegenerators.PrefixingPageGenerator(prefix="Wikipedia Asian Month/Onsite edit-a-thon/", site=site, includeredirects=False)
for page in gen:
    title = page.title()
    print(title)
    newtitle = title.replace("Wikipedia Asian Month/Onsite edit-a-thon/", "Wikipedia Asian Month 2016/Onsite edit-a-thon/")
    if pywikibot.Page(site,newtitle).exists():
        print("Target already exist")
    else:
        page.move(newtitle, reason="move 2016 WAM pages from WAM to WAM 2016", noredirect=True)
        print("moved to", newtitle)
Wikipedia Asian Month/Onsite edit-a-thon/Cologne
moved to Wikipedia Asian Month 2016/Onsite edit-a-thon/Cologne
Wikipedia Asian Month/Onsite edit-a-thon/Hsinchu
Sleeping for 9.5 seconds, 2019-07-13 16:25:46
moved to Wikipedia Asian Month 2016/Onsite edit-a-thon/Hsinchu
Wikipedia Asian Month/Onsite edit-a-thon/Kolkata
Sleeping for 9.5 seconds, 2019-07-13 16:25:56
moved to Wikipedia Asian Month 2016/Onsite edit-a-thon/Kolkata
Wikipedia Asian Month/Onsite edit-a-thon/Munich
Sleeping for 9.5 seconds, 2019-07-13 16:26:06
moved to Wikipedia Asian Month 2016/Onsite edit-a-thon/Munich
Wikipedia Asian Month/Onsite edit-a-thon/Taichung
Sleeping for 9.6 seconds, 2019-07-13 16:26:16
moved to Wikipedia Asian Month 2016/Onsite edit-a-thon/Taichung