summary = "Moving item pages"

# really, more like, skipped...
failed = []

# Goal: Move all item files from File:itemname.png to File:ItemSquareitemname.png
# Discovery is by looking at pages in Category:Items and finding files named
# after these pages, because our item files aren't all properly categorized
# After doing this I'm going to run a separate script to properly categorize
# all of the item files (probably I should have done that at the same time but meh lol)

try:
    for page in site.client.categories['Items']:
        page: Page
        name: str = page.name.replace(' (Item)', '')
        print('Starting {}'.format(name))
        file = site.client.pages['File:{}.png'.format(name)]
        if not file.exists:
            failed.append(name)
            continue
        if 'redirect' in file.text().lower():
            continue
        site.move(file, 'File:ItemSquare{}.png'.format(name))
except Exception as e:
    print(failed)
    print(e.__traceback__)

print('Printing failed items...')

print(failed)
示例#2
0
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)