Utente:BimBot/Scripts
Da Wikiquote, aforismi e citazioni in libertà.
redirect_nemo.py [modifica]
- Ultimo passaggio: ottobre 2010, con Italoautoma. Elenco delle voci e relative opere; Rimandi cancellati, tendenzialmente da non ricreare.
#!/usr/bin/env python # -*- coding: utf-8 -*- import re, wikipedia def main(): args = wikipedia.handleArgs() all = False for currentArgument in args: if currentArgument.startswith("-always"): all = True site = wikipedia.getSite('it', 'wikiquote') genPage = wikipedia.Page(site, "Utente:Nemo bis/Elenco titoli") wikipedia.setAction("") # Oggetto automatico for i in genPage.linkedPages(): wikipedia.output("From page: " + i.title()) iText = i.get() sezioni = re.findall(r"(?m)^(==+)\s*(''|''''')\s*(.*?)\s*\2\s*\1\s*$", iText) for j in sezioni: redir = wikipedia.Page(site, j[2].replace('[[', '').replace(']]', '').replace("''", "''")) # Toglie i link e il corsivo wikipedia.output(">>>>> " + redir.title() + " <<<<<") if redir.exists(): wikipedia.output("The page already exists. Skipping.") continue newtext = "#REDIRECT[[" + i.title() + "#" + redir.title() + "]]" wikipedia.showDiff('', newtext) if not all: choice = wikipedia.inputChoice(u"Creo redirect?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N') else: choice = 'y' if choice in ['A', 'a']: all = True choice = 'y' if choice in ['Y', 'y']: redir.put_async(newtext) if __name__ == "__main__": try: main() finally: wikipedia.stopme()