Usuari:VriuBot/separadors.py: diferència entre les revisions

De Viccionari
Contingut suprimit Contingut afegit
acreditació de l'autor
m autor
Línia 5: Línia 5:
#Este script reemplaça els punts per punts volats com a separadors de síl·labes.
#Este script reemplaça els punts per punts volats com a separadors de síl·labes.


#Autor: Pasqual
#Autor: Coet (abans, Pasqual)


#OPCIONS PERSONALITZABLES
#OPCIONS PERSONALITZABLES

Revisió del 11:41, 1 jul 2013

#/usr/bin/python2.5
#-*- encoding: utf-8 -*-

#Este script reemplaça els punts per punts volats com a separadors de síl·labes.

#Autor: Coet (abans, Pasqual)

#OPCIONS PERSONALITZABLES
primera = "!" #en cas d'aturar el bot poseu aquí el darrer mot analitzat
resum   = u"Bot: canviant separador de síl·labes"
edit    = False #per a que el bot edite canvieu el valor d'esta variable a True
informa = True #per a visualitzar els canvis el valor ha de ser True
 
#A PARTIR D'ACÍ NO MODIFIQUEU RES
import wikipedia, pagegenerators, re
 
site = wikipedia.getSite("ca", "wiktionary")
gen = pagegenerators.AllpagesPageGenerator(site=site, start=primera, namespace=0)
preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber = 60)

def sep_ort():
    for pag in preloadingGen:
        try:
            wikipedia.output(u"\3{lightblue}"+pag.title())
            if not pag.exists():
                continue
            txt=pag.get()
            regexp=re.search("\n'''([^']+\.(?:[^']+\.)*?[^'.]+)'''",txt)
            if regexp:
                sepsil = regexp.group(1)
                nova_sepsil = sepsil.replace(".",u"·")
                nou_txt = txt.replace(sepsil, nova_sepsil)
                if informa: wikipedia.showDiff(txt, nou_txt)
                if edit: pag.put(nou_txt, resum)
        except wikipedia.IsRedirectPage:
            continue
        except KeyboardInterrupt:
            break

def sep_fon():
    for pag in preloadingGen:
        try:
            wikipedia.output(pag.title())
            if not pag.exists():
                continue
            txt=nou_txt=pag.get()
            matches=re.findall(ur"\| */([^·]+·(?:[^·]+·)*?[^·]+)/ *\}\}",txt)
            if matches:
                for sepsil in matches:
                    nova_sepsil = sepsil.replace(u"·",".")
                    nou_txt = nou_txt.replace(sepsil, nova_sepsil)
            if nou_txt != txt:
                if informa: wikipedia.showDiff(txt, nou_txt)
                if edit: pag.put(nou_txt, resum)
        except wikipedia.IsRedirectPage:
            continue
        except KeyboardInterrupt:
            break
sep_fon()
wikipedia.stopme()