Exemplo n.º 1
0
def main():
    wikipedia.handleArgs();

    page = wikipedia.Page(wikipedia.getSite(), cfdPage)

    # Variable declarations
    day = "None"
    mode = "None"
    src = "None"
    dest = "None"
    line = ""
    summary = ""
    robot = None

    m = ReCheck()
    for line in page.get().split("\n"):
        if (nobots.search(line)):
            # NO BOTS!!!
            pass
        elif (example.search(line)):
            # Example line
            pass
        elif (speedymode.search(line)):
            mode = "Speedy"
            day = "None"
        elif (movemode.search(line)):
            mode = "Move"
            day = "None"
        elif (emptymode.search(line)):
            mode = "Empty"
            day = "None"
        elif (deletemode.search(line)):
            mode = "Delete"
            day = "None"
        elif (maintenance.search(line)):
            # It's probably best not to try to handle these in an automated fashion.
            mode = "None"
            day = "None"
        elif (m.check(dateheader, line)):
            day = m.result.group(1)
        elif (m.check(movecat, line)):
            src = m.result.group(1)
            dest = m.result.group(2)
            if (mode == "Move" and day != "None"):
                summary = "Robot - Moving category " + src + " to " + dest + " per [[WP:CFD|CFD]] at " + findDay(src, day) + "."
            elif (mode == "Speedy"):
                summary = "Robot - Speedily moving category " + src + " to " + dest + " per [[WP:CFD|CFD]]."
            else:
                continue
            # If the category is redirect, we do NOT want to move articles to
            # it. The safest thing to do here is abort and wait for human
            # intervention.
            destpage = wikipedia.Page(
                wikipedia.getSite(), dest, defaultNamespace=14)
            if destpage.isCategoryRedirect():
                summary = 'CANCELED. Destination is redirect: ' + summary
                wikipedia.output(summary, toStdout=True)
                robot = None
            else:
                robot = category.CategoryMoveRobot(oldCatTitle=src, newCatTitle=dest, batchMode=True,
                                                   editSummary=summary, inPlace=True, moveCatPage=True,
                                                   deleteEmptySourceCat=True)
        elif (m.check(deletecat, line)):
            src = m.result.group(1)
            # I currently don't see any reason to handle these two cases separately, though
            # if are guaranteed that the category in the "Delete" case is empty, it might be
            # easier to call delete.py on it.
            if ((mode == "Empty" or mode == "Delete") and day != "None"):
                summary = "Robot - Removing category " + src + " per [[WP:CFD|CFD]] at " + findDay(src, day) + "."
            else:
                continue
            robot = category.CategoryRemoveRobot(catTitle=src, batchMode=True, editSummary=summary,
                                                 useSummaryForDeletion=True, inPlace=True)
        else:
            # This line does not fit any of our regular expressions, so ignore it.
            pass
        if (summary != "" and robot != None):
            wikipedia.output(summary, toStdout=True)
            # Run, robot, run!
            robot.run()
        summary = ""
        robot = None
Exemplo n.º 2
0
def main(*args):
    # The location of the CFD working page.
    cfdPage = 'Wikipedia:Categories for discussion/Working'
    for arg in pywikibot.handleArgs(*args):
        # Use a non-default CFD working page if one is specified from the command-line using -page.
        if arg.startswith('-page'):
            if len(arg) == len('-page'):
                cfdPage = pywikibot.input(
                    u'Enter the CFD working page to use:')
            else:
                cfdPage = arg[len('-page:'):].replace('_', ' ')

    page = pywikibot.Page(pywikibot.getSite(), cfdPage)

    # Variable declarations
    day = "None"
    mode = "None"
    src = "None"
    dest = "None"
    line = ""
    summary = ""
    robot = None

    m = ReCheck()
    for line in page.get().split("\n"):
        if nobots.search(line):
            # NO BOTS!!!
            pass
        elif example.search(line):
            # Example line
            pass
        elif speedymode.search(line):
            mode = "Speedy"
            day = "None"
        elif movemode.search(line):
            mode = "Move"
            day = "None"
        elif emptymode.search(line):
            mode = "Empty"
            day = "None"
        elif deletemode.search(line):
            mode = "Delete"
            day = "None"
        elif maintenance.search(line):
            # It's probably best not to try to handle these in an automated
            # fashion.
            mode = "None"
            day = "None"
        elif m.check(dateheader, line):
            day = m.result.group(1)
            pywikibot.output("Found day header: %s" % day)
        elif m.check(movecat, line):
            src = m.result.group(1)
            dest = m.result.group(2)
            thisDay = findDay(src, day)
            if mode == "Move" and thisDay != "None":
                summary = (
                    "Robot - Moving category %s to [[:Category:%s]] per "
                    "[[WP:CFD|CFD]] at %s.") % (src, dest, thisDay)
            elif mode == "Speedy":
                summary = ("Robot - Speedily moving category %s to "
                           "[[:Category:%s]] per [[WP:CFDS|CFDS]].") % (src,
                                                                        dest)
            else:
                continue
            # If the category is redirect, we do NOT want to move articles to
            # it. The safest thing to do here is abort and wait for human
            # intervention.
            destpage = pywikibot.Page(pywikibot.getSite(),
                                      dest,
                                      defaultNamespace=14)
            if destpage.isCategoryRedirect():
                summary = 'CANCELED. Destination is redirect: ' + summary
                pywikibot.output(summary, toStdout=True)
                robot = None
            else:
                robot = category.CategoryMoveRobot(oldCatTitle=src,
                                                   newCatTitle=dest,
                                                   batchMode=True,
                                                   editSummary=summary,
                                                   inPlace=True,
                                                   moveCatPage=True,
                                                   deleteEmptySourceCat=True,
                                                   useSummaryForDeletion=True)
        elif m.check(deletecat, line):
            src = m.result.group(1)
            # I currently don't see any reason to handle these two cases
            # separately, though if are guaranteed that the category in the
            # "Delete" case is empty, it might be easier to call delete.py on
            # it.
            thisDay = findDay(src, day)
            if (mode == "Empty" or mode == "Delete") and thisDay != "None":
                summary = ("Robot - Removing category %s per [[WP:CFD|CFD]] "
                           "at %s.") % (src, thisDay)
            else:
                continue
            robot = category.CategoryRemoveRobot(catTitle=src,
                                                 batchMode=True,
                                                 editSummary=summary,
                                                 useSummaryForDeletion=True,
                                                 inPlace=True)
        else:
            # This line does not fit any of our regular expressions, so ignore
            # it.
            pass
        if summary != "" and robot is not None:
            pywikibot.output(summary, toStdout=True)
            # Run, robot, run!
            robot.run()
        summary = ""
        robot = None