Jump to content

User:FrostlyBot/code

From Wikipedia, the free encyclopedia

# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install mwparserfromhell mwclient
from mwparserfromhell import Site
site = Site('en.wikipedia.org')
site.login('my_username', 'my_password')

category = site.categories['Pages using infobox lighthouse with deprecated parameters']
for page in category:
    print(page.name)
    text = page.text
    # text = "{{Infobox lighthouse|Admiralty=Awesome!|relief=yeah}}"
    code = mwparserfromhell.parse(text)
    for template in code.filter_templates():
        if template.name.matches("Infobox lighthouse"):
            if template.has("Admiralty"):
                template.remove("Admiralty")
            if template.has("ARLHS"):
                template.remove("ARLHS")
            if template.has("Canada"):
                template.remove("Canada")
            if template.has("coordinates_footnotes"):
                template.remove("coordinates_footnotes")
            if template.has("NGA"):
                template.remove("NGA")
            if template.has("pushpin"):
                template.remove("pushpin")
            if template.has("pushpin_label_position"):
                template.remove("pushpin_label_position")
            if template.has("pushpin_map"):
                template.remove("pushpin_map")
            if template.has("pushpin_map_alt"):
                template.remove("pushpin_map_alt")
            if template.has("pushpin_map_caption"):
                template.remove("pushpin_map_caption")
            if template.has("pushpin_mapsize"):
                template.remove("pushpin_mapsize")
            if template.has("pushpin_outside"):
                template.remove("pushpin_outside")
            if template.has("pushpin_relief"):
                template.remove("pushpin_relief")
            if template.has("relief"):
                template.remove("relief")
            if template.has("USCG"):
                template.remove("USCG")
            print(code)
            page.edit(code, 'Removing deprecated parameters from [[Template:Infobox lighthouse]] (BOT, in trial)')