Esempio n. 1
0
    def addCommonscat(self, page):
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        pywikibot.output(u'Working on ' + page.title())
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.code)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output(u'Commonscat template is already on %s' %
                             page.title())
            (currentCommonscatTemplate, currentCommonscatTarget, LinkText,
             Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(
                    u'Commonscat link at %s to Category:%s is ok' %
                    (page.title(), currentCommonscatTarget))
                return (True, self.always)
            elif checkedCommonscatTarget != u'':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return (True, self.always)
            else:
                # Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != u''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                # TODO: if the commonsLink == u'', should it be removed?

        elif self.skipPage(page):
            pywikibot.output("Found a template in the skip list. Skipping %s" %
                             page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != u''):
                if commonscatLink == page.title():
                    textToAdd = u'{{%s}}' % primaryCommonscat
                else:
                    textToAdd = u'{{%s|%s}}' % (primaryCommonscat,
                                                commonscatLink)
                (success, status,
                 self.always) = add_text.add_text(page, textToAdd,
                                                  self.summary, None, None,
                                                  self.always)
                return (True, self.always)
        return (True, self.always)
Esempio n. 2
0
    def addCommonscat(self, page):
        """
        Add CommonsCat template to page.

        Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        self.current_page = page
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.code)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output(u'Commonscat template is already on %s'
                             % page.title())
            (currentCommonscatTemplate,
             currentCommonscatTarget, LinkText, Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(u'Commonscat link at %s to Category:%s is ok'
                                 % (page.title(), currentCommonscatTarget))
                return True
            elif checkedCommonscatTarget != u'':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return True
            else:
                # Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != u''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                # TODO: if the commonsLink == u'', should it be removed?

        elif self.skipPage(page):
            pywikibot.output("Found a template in the skip list. Skipping %s"
                             % page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != u''):
                if commonscatLink == page.title():
                    textToAdd = u'{{%s}}' % primaryCommonscat
                else:
                    textToAdd = u'{{%s|%s}}' % (primaryCommonscat,
                                                commonscatLink)
                rv = add_text(page, textToAdd,
                              self.getOption('summary'),
                              always=self.getOption('always'))
                self.options['always'] = rv[2]
                return True
        return True
Esempio n. 3
0
    def addCommonscat(self, page):
        """Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        pywikibot.output(u'Working on ' + page.title())
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.language())
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output(u'Commonscat template is already on %s'
                             % page.title())
            (currentCommonscatTemplate,
             currentCommonscatTarget, LinkText, Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(u'Commonscat link at %s to Category:%s is ok'
                                 % (page.title(), currentCommonscatTarget))
                return (True, self.always)
            elif checkedCommonscatTarget != u'':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return (True, self.always)
            else:
                #Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != u''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                #else
                #Should i remove the commonscat link?

        elif self.skipPage(page):
            pywikibot.output("Found a template in the skip list. Skipping %s"
                             % page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != u''):
                if commonscatLink == page.title():
                    textToAdd = u'{{%s}}' % primaryCommonscat
                else:
                    textToAdd = u'{{%s|%s}}' % (primaryCommonscat,
                                                commonscatLink)
                (success, status, self.always) = add_text.add_text(page,
                                                                   textToAdd,
                                                                   self.summary,
                                                                   None, None,
                                                                   self.always)
                return (True, self.always)
        return (True, self.always)
Esempio n. 4
0
    def addCommonscat(self, page):
        """Take a page. Go to all the interwiki page looking for a commonscat
        template. When all the interwiki's links are checked and a proper
        category is found add it to the page.

        """
        self.current_page = page
        # Get the right templates for this page
        primaryCommonscat, commonscatAlternatives = self.getCommonscatTemplate(
            page.site.code)
        commonscatLink = self.getCommonscatLink(page)
        if commonscatLink:
            pywikibot.output(u'Commonscat template is already on %s'
                             % page.title())
            (currentCommonscatTemplate,
             currentCommonscatTarget, LinkText, Note) = commonscatLink
            checkedCommonscatTarget = self.checkCommonscatLink(
                currentCommonscatTarget)
            if (currentCommonscatTarget == checkedCommonscatTarget):
                # The current commonscat link is good
                pywikibot.output(u'Commonscat link at %s to Category:%s is ok'
                                 % (page.title(), currentCommonscatTarget))
                return True
            elif checkedCommonscatTarget != u'':
                # We have a new Commonscat link, replace the old one
                self.changeCommonscat(page, currentCommonscatTemplate,
                                      currentCommonscatTarget,
                                      primaryCommonscat,
                                      checkedCommonscatTarget, LinkText, Note)
                return True
            else:
                #Commonscat link is wrong
                commonscatLink = self.findCommonscatLink(page)
                if (commonscatLink != u''):
                    self.changeCommonscat(page, currentCommonscatTemplate,
                                          currentCommonscatTarget,
                                          primaryCommonscat, commonscatLink)
                #else
                #Should i remove the commonscat link?

        elif self.skipPage(page):
            pywikibot.output("Found a template in the skip list. Skipping %s"
                             % page.title())
        else:
            commonscatLink = self.findCommonscatLink(page)
            if (commonscatLink != u''):
                if commonscatLink == page.title():
                    textToAdd = u'{{%s}}' % primaryCommonscat
                else:
                    textToAdd = u'{{%s|%s}}' % (primaryCommonscat,
                                                commonscatLink)
                always = self.getOption('always')
                rv = add_text(page, textToAdd, self.summary, always=always)
                self.options['always'] = rv[2]
                return True
        return True
Esempio n. 5
0
def main():
    args = wikipedia.handleArgs()
    all = False
    genFactory = pagegenerators.GeneratorFactory()
    
    for currentArgument in args:   
        if currentArgument.startswith("-always"):
            all = True
        else:
            generator = genFactory.handleArg(currentArgument)
              
    # Check if pages on which the bot should work are specified.
    if not generator:
        raise Exception('You have to specify which pages the script has to work on!')
    
    # Main Loop
    for i in generator:
        attenzioneIo = False # Dubbio su "I", che può essere articolo determinativo italiano o pronome personale inglese
        titolo = i.title()
        wikipedia.output(">>>>> " + titolo + " <<<<<")
          
        nuovoTitolo = re.sub("^(The |A |An |Il |Lo |La |I |Gli |Le |L'|Uno |Una |Un'|Un )([A-Z0-9].*)", r"{{DEFAULTSORT:\2, \1}}", titolo)
        if titolo == nuovoTitolo:
            wikipedia.output("Non c'è nessun articolo. Prossima pagina...")
            continue
        
        if re.search("^I ", titolo):
            attenzioneIo = True
                
        nuovoTitolo = re.sub("[ ']\}\}", "}}", nuovoTitolo) # Toglie spazi, apostrofi...
        
        try:
            oldtext = i.get()
        except wikipedia.IsRedirectPage:
            wikipedia.output(u"%s is a redirect, I'll ignore it." % i.title())
            continue
        
        if re.search("\{\{DEFAULTSORT:", oldtext):
            wikipedia.output("C'è già un DEFAULTSORT. Prossima pagina...")
            continue
            
        newtext = add_text(page = i, addText = nuovoTitolo, putText = False, oldTextGiven = oldtext)[1]
        wikipedia.showDiff(oldtext, newtext)
        if not all or attenzioneIo:
            choice = wikipedia.inputChoice(u"Modificare?",  ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
        else:
            choice = 'y'
        if choice in ['A', 'a']:
            all = True
            choice = 'y'
        if choice in ['Y', 'y']:
            i.put_async(newtext, comment="Aggiungo: " + nuovoTitolo)    
Esempio n. 6
0
def addCommonscat (page = None, summary = None, always = False):
    '''
    Take a page. Go to all the interwiki page looking for a commonscat template.
    When all the interwiki's links are checked and a proper category is found
    add it to the page.
    '''
    pywikibot.output(u'Working on ' + page.title());
    #Get the right templates for this page
    primaryCommonscat, commonscatAlternatives = getCommonscatTemplate(
        page.site().language())
    commonscatLink = getCommonscatLink (page)
    if commonscatLink:
        pywikibot.output(u'Commonscat template is already on %s'
                         % page.title())
        (currentCommonscatTemplate, currentCommonscatTarget) = commonscatLink
        checkedCommonscatTarget = checkCommonscatLink(currentCommonscatTarget)
        if (currentCommonscatTarget==checkedCommonscatTarget):
            #The current commonscat link is good
            pywikibot.output(u'Commonscat link at %s to Category:%s is ok'
                             % (page.title() , currentCommonscatTarget));
            return (True, always)
        elif checkedCommonscatTarget!=u'':
            #We have a new Commonscat link, replace the old one
            changeCommonscat(page, currentCommonscatTemplate,
                             currentCommonscatTarget, primaryCommonscat,
                             checkedCommonscatTarget)
            return (True, always)
        else:
            #Commonscat link is wrong
            commonscatLink = findCommonscatLink(page)
            if (commonscatLink!=u''):
                changeCommonscat (page, currentCommonscatTemplate,
                                  currentCommonscatTarget, primaryCommonscat,
                                  commonscatLink)
            #else
            #Should i remove the commonscat link?

    elif skipPage(page):
        pywikibot.output("Found a template in the skip list. Skipping %s"
                         % page.title());
    else:
        commonscatLink = findCommonscatLink(page)
        if (commonscatLink!=u''):
            textToAdd = u'{{' + primaryCommonscat + u'|' + commonscatLink + u'}}'
            (success, status, always) = add_text.add_text(page, textToAdd,
                                                          summary, None, None,
                                                          always);
            return (True, always);

    return (True, always);
Esempio n. 7
0
def addCommonscat(page=None, summary=None, always=False):
    """
    Take a page. Go to all the interwiki page looking for a commonscat template.
    When all the interwiki's links are checked and a proper category is found add it to the page.
    """
    wikipedia.output(u"Working on " + page.title())
    # Get the right templates for this page
    primaryCommonscat, commonscatAlternatives = getCommonscatTemplate(page.site().language())
    commonscatLink = getCommonscatLink(page)
    if commonscatLink:
        wikipedia.output(u"Commonscat template is already on " + page.title())
        (currentCommonscatTemplate, currentCommonscatTarget) = commonscatLink
        checkedCommonscatTarget = checkCommonscatLink(currentCommonscatTarget)
        if currentCommonscatTarget == checkedCommonscatTarget:
            # The current commonscat link is good
            wikipedia.output(
                u"Commonscat link at " + page.title() + u" to Category:" + currentCommonscatTarget + u" is ok"
            )
            return (True, always)
        elif checkedCommonscatTarget != u"":
            # We have a new Commonscat link, replace the old one
            changeCommonscat(
                page, currentCommonscatTemplate, currentCommonscatTarget, primaryCommonscat, checkedCommonscatTarget
            )
            return (True, always)
        else:
            # Commonscat link is wrong
            commonscatLink = findCommonscatLink(page)
            if commonscatLink != u"":
                changeCommonscat(
                    page, currentCommonscatTemplate, currentCommonscatTarget, primaryCommonscat, commonscatLink
                )
            # else
            # Should i remove the commonscat link?

    elif skipPage(page):
        wikipedia.output("Found a template in the skip list. Skipping " + page.title())
    else:
        commonscatLink = findCommonscatLink(page)
        if commonscatLink != u"":
            textToAdd = u"{{" + primaryCommonscat + u"|" + commonscatLink + u"}}"
            (success, status, always) = add_text.add_text(page, textToAdd, summary, None, None, always)
            return (True, always)

    return (True, always)
Esempio n. 8
0
def addCommonscat (page = None, summary = None, always = False):
    '''
    Take a page. Go to all the interwiki page looking for a commonscat template.
    When all the interwiki's links are checked and a proper category is found add it to the page.
    '''
    wikipedia.output(u'Working on ' + page.title());
    #Get the right templates for this page
    primaryCommonscat, commonscatAlternatives=getCommonscatTemplate(page.site().language())
    commonscatLink = getCommonscatLink (page)
    if commonscatLink:
        wikipedia.output(u'Commonscat template is already on ' + page.title());
        (currentCommonscatTemplate, currentCommonscatTarget) = commonscatLink
        checkedCommonscatTarget = checkCommonscatLink(currentCommonscatTarget)
        if (currentCommonscatTarget==checkedCommonscatTarget):
            #The current commonscat link is good
            wikipedia.output(u'Commonscat link at ' + page.title() + u' to Category:' + currentCommonscatTarget + u' is ok');
            return (True, always)
        elif checkedCommonscatTarget!=u'':
            #We have a new Commonscat link, replace the old one
            changeCommonscat (page, currentCommonscatTemplate, currentCommonscatTarget, primaryCommonscat, checkedCommonscatTarget)
            return (True, always)
        else:
            #Commonscat link is wrong
            commonscatLink = findCommonscatLink(page)
            if (commonscatLink!=u''):
                changeCommonscat (page, currentCommonscatTemplate, currentCommonscatTarget, primaryCommonscat, commonscatLink)
            #else
            #Should i remove the commonscat link?

    elif skipPage(page):
        wikipedia.output("Found a template in the skip list. Skipping " + page.title());
    else:
        commonscatLink = findCommonscatLink(page)
        if (commonscatLink!=u''):
            textToAdd = u'{{' + primaryCommonscat + u'|' + commonscatLink + u'}}'
            (success, status, always) = add_text.add_text(page, textToAdd, summary, None, None, always);
            return (True, always);

    return (True, always);
Esempio n. 9
0
def addCommonscat (page = None, summary = None, always = False):
    '''
    Take a page. Go to all the interwiki page looking for a commonscat template.
    When all the interwiki's links are checked and a proper category is found add it to the page.
    '''

    wikipedia.output(u'Working on ' + page.title());
    if getTemplate(page.site().language()) in page.templates():
        wikipedia.output(u'Commonscat template is already on ' + page.title());
        currentCommonscat = getCommonscatLink (page)
        checkedCommonscat = checkCommonscatLink(currentCommonscat)
        if (currentCommonscat==checkedCommonscat):
            #The current commonscat link is good
            wikipedia.output(u'Commonscat link at ' + page.title() + u' to Category:' + currentCommonscat + u' is ok');
            return (True, always)
        elif checkedCommonscat!=u'':
            #We have a new Commonscat link, replace the old one
            changeCommonscat (page, currentCommonscat, checkedCommonscat)
            return (True, always)
        else:
            #Commonscat link is wrong
            commonscatLink = findCommonscatLink(page)
            if (commonscatLink!=u''):
                changeCommonscat (page, currentCommonscat, commonscatLink)
            #else
            #Should i remove the commonscat link?

    elif skipPage(page):
        wikipedia.output("Found a template in the skip list. Skipping " + page.title());
    else:
        commonscatLink = findCommonscatLink(page)
        if (commonscatLink!=u''):
            textToAdd = u'{{' + getTemplate(page.site().language()) + u'|' + commonscatLink + u'}}'
            (success, always) = add_text.add_text(page, textToAdd, summary, None, None, always);
            return (True, always);

    return (True, always);