Purple exclamation mark.svg Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.

Red exclamation mark.svg UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.

Python:Monitoraggio logic.py

From Botwiki
Jump to: navigation, search

It works in couple with Python:Monitoraggio bot.py.

# Scribbles by valhallasw
# MIT licensed
 
import re
import wikipedia
 
itwiki = wikipedia.getSite('it', 'wikipedia')
 
standardparams = {
    u"progetto": u"",
    u"progetto2": u"",
    u"accuratezza": u"",
    u"scrittura": u"",
    u"fonti": u"",
    u"immagini": u"",
    u"note": u"",
    u"utente": u"{{subst:REVISIONUSER}}",
    u"data": u"{{subst:CURRENTMONTH}} {{subst:CURRENTYEAR}}"
}
 
order = ("progetto", "progetto2", "accuratezza", "scrittura", "fonti", "immagini", "note", "utente", "data")
 
def parsePage(p):
    params = standardparams.copy()
    summarytexts = []
 
    text = p.get()
    includedtemplates = p.getTemplates()
 
    ##################################################################
 
    """If there are no images in the article set "immagini" parameter to "x". add to the summary "Nessuna immagine;" """
 
    imagelinks = p.imagelinks(loose=True)
 
    if len(imagelinks) == 0:
        """ Note: this does loose matching, so it might match images
            that are not actually images. However, we only mark it as
            BAD if there are no images, not as GOOD if there are, so
            this is safe """
        params[u"immagini"] = u"x"
        summarytexts.append(u"Nessuna immagine")
 
    ##################################################################
 
    """if there is no <ref> nor a section named "[^=]*[Bb]ibliografia[^=]*" set "fonti" to "x". add to the summary "Nessuna fonte;" """
 
    hasref = u"<ref>" in text
    hasbib = re.findall(ur" *=+ *bibliografia *=* *", text, re.IGNORECASE)
 
    if (not hasref) and (not hasbib):
        params[u"fonti"] = u"x"
        summarytexts.append(u"Nessuna fonte")
 
    ##################################################################
 
    """ if there are refs but not "[^=]*[Bb]ibliografia[^=]*" section, set fonti to "d". add to the summary "Nessuna sezione bibliografica rilevata;" """
 
    if hasref and (not hasbib):
        params[u"fonti"] = u"d"
        summarytexts.append(u"Nessuna sezione bibliografica rilevata")
 
    ##################################################################
 
    """ if there are both refs and "[^=]*[Bb]ibliografia[^=]*" section, there is not {{F}} nor {{NN}} nor {{senza fonte}} templates (nor their redirect templates) and there are more than 10 <ref>, set fonti to "b". add to the summary "Nessun problema di fonti rilevato;" """
 
    hasF  = wikipedia.Page(itwiki, 'Template:F')  in includedtemplates
    hasNN = wikipedia.Page(itwiki, 'Template:NN') in includedtemplates
    hasSF = wikipedia.Page(itwiki, 'Template:senza fonte') \
                                                  in includedtemplates
    numref = len(re.findall(ur'\<ref\>', p.get()))
 
    if (not hasF) and (not hasNN) and (not hasSF) and (numref > 10):
        params[u"fonti"] = u"b"
        summarytexts.append(u"Nessun problema di fonti rilevato")
 
    ##################################################################
 
    """ if there are {{da correggere}} or {{W}} template (or their redirect templates), set scrittura to "x". add to the summary "scrittura da correggere;" """
 
    hasDC = wikipedia.Page(itwiki, 'Template:da corregere') \
                                                  in includedtemplates
    hasW  = wikipedia.Page(itwiki, 'Template:W')  in includedtemplates
 
    if (hasDC) or (hasW):
        params[u"scrittura"] = u"x"
        summarytexts.append(u"Scrittura da correggere")
 
    ##################################################################
 
    """ if there are {{A}},or {{E}}, {{P}}, {{C}} templates (or their redirect templates), set accuratezza to "x". add to the summary "presenza di avvisi che pregiudicano l'accuratezza;" """
 
    hasA  = wikipedia.Page(itwiki, 'Template:A') in includedtemplates
    hasE  = wikipedia.Page(itwiki, 'Template:E') in includedtemplates
    hasP  = wikipedia.Page(itwiki, 'Template:P') in includedtemplates
    hasC  = wikipedia.Page(itwiki, 'Template:C') in includedtemplates
 
    if (hasA) or (hasE) or (hasP) or (hasC):
        params[u"accuratezza"] = u"x"
        summarytexts.append(u"Presenza di avvisi che pregiudicano l'accuratezza")
 
    suggestedtemplate = u"{{Monitoraggio\n" + u"\n".join([u"|%s = %s" % (a,params[a]) for a in order]) + u"\n}}"
    suggestedsummary  = u"Bot:Valutazione"
    if len(summarytexts) > 0:
        suggestedsummary += u": " + "; ".join(summarytexts)
 
    return (suggestedsummary, suggestedtemplate)
Personal tools
Share