credentials = AuthCredentials(user_file="bot") site = EsportsClient('lol', credentials=credentials, max_retries=10) summary = "Moving item pages" for page in site.client.categories['Items']: page: Page name: str = page.name print(name) if not name.endswith('(Item)'): continue if page.namespace != 0: continue clean_name = page.name.replace(' (Item)', '') clean_page = site.client.pages[clean_name] clean_page_text = clean_page.text() if clean_page.exists and 'redirect' not in clean_page_text.lower(): continue print('Moving to {}'.format(clean_name)) # Delete and then move because the redirect has a history so we get an error, even with ignore_warnings if clean_page.exists: site.delete(clean_page) mh_page: Page = site.client.pages[name + '/Match History'] if mh_page.exists: clean_mh_page = site.client.pages[clean_name + '/Match History'] if clean_mh_page.exists: site.delete(clean_mh_page) # at this time, move_subpages=True is in my fork of mwclient, I have a PR to upstream to merge it in site.move(page, clean_name, move_subpages=True)
# batch job, there were over 300 double redirects to fix, and I'd rather not # have that happening, so I'm just going to delete all unused redirects now. # For example, we had a bunch of Chinese names of items existing due to a # failed experiment in the past to create scoreboards with Chinese item names # entered in them - these redirects are totally unneeded at this point in time, # and there's literally no reason to keep them around anymore. for page in site.client.categories['Item Icons']: page: Image print('Starting page {}...'.format(page.name)) for link in page.backlinks(redirect=True): print(link.name) link: Image if not link.redirect: continue i = 0 # note because `link` is a file, and not a page, we MUST use imageusage and NOT backlinks here to check usage # link.backlinks() will return no results for backlink in link.imageusage(): backlink: Page i += 1 if i == 0: print('Deleting backlink {}...'.format(link.name)) site.delete(link) # rate-limit myself so I can verify the code is actually working. # after verifying it works, I comment this out and re-run without any limiting. # time.sleep(5)