Example #1
0
def main(*args):
    options = {}
    local_args = pywikibot.handle_args(args)
    genFactory = pagegenerators.GeneratorFactory()
    for arg in local_args:
        if genFactory.handleArg(arg):
            continue
        if arg.startswith('-'):
            arg, sep, value = arg.partition(':')
            if value != '':
                options[arg[1:]] = value if not value.isdigit() else int(value)
            else:
                options[arg[1:]] = True

    generator = genFactory.getCombinedGenerator(preload=True)
    site = pywikibot.Site()
    if not generator:
        try:
            category = site.page_from_repository('Q11925744')
        except (NotImplementedError, UnknownExtension) as e:
            pywikibot.error(e)
            return

        if not category:
            pywikibot.output("%s doesn't have an appropriate category" % site)
            return

        gen_combined = pagegenerators.CombinedPageGenerator(
            [category.articles(namespaces=0),
             category.subcategories()])
        generator = pagegenerators.WikibaseItemFilterPageGenerator(
            gen_combined)

    bot = CommonscatCleaningBot(generator, site=site, **options)
    bot.run()
Example #2
0
 def generator(self):
     """Generator method."""
     gens = [t.getReferences(follow_redirects=True, namespaces=[6],
                             onlyTemplateInclusion=True)
             for t in self.nc_templates]
     gen = pg.CombinedPageGenerator(gens)
     gen = pg.DuplicateFilterPageGenerator(gen)
     gen = pg.PreloadingGenerator(gen)
     return gen
Example #3
0
 def getPageGenerator(self):
     if self.getOption('use_hash'):
         gen = self.useHashGenerator()
     else:
         gens = [
             t.getReferences(follow_redirects=True,
                             namespaces=[6],
                             onlyTemplateInclusion=True)
             for t in self.nc_templates
         ]
         gen = pg.CombinedPageGenerator(gens)
         gen = pg.DuplicateFilterPageGenerator(gen)
         gen = pg.PreloadingGenerator(gen)
     return gen
Example #4
0
 def getPageGenerator(self):
     if self.getOption('use_hash'):
         gen = self.useHashGenerator()
     else:
         nowCommonsTemplates = [pywikibot.Page(self.site, title,
                                               ns=10)
                                for title in self.ncTemplates()]
         gens = [pg.ReferringPageGenerator(t, followRedirects=True,
                                           onlyTemplateInclusion=True)
                 for t in nowCommonsTemplates]
         gen = pg.CombinedPageGenerator(gens)
         gen = pg.NamespaceFilterPageGenerator(gen, [6])
         gen = pg.DuplicateFilterPageGenerator(gen)
         gen = pg.PreloadingGenerator(gen)
     return gen
Example #5
0
    def createPageGenerator(self, firstPageTitle):
        """
        Generator to retrieve misspelling pages or misspelling redirects.

        @rtype: generator
        """
        mylang = self.site.code
        if mylang in self.misspellingCategory:
            categories = self.misspellingCategory[mylang]
            if isinstance(categories, basestring):
                categories = (categories, )
            generators = (
                pagegenerators.CategorizedPageGenerator(
                    pywikibot.Category(self.site, misspellingCategoryTitle),
                    recurse=True, start=firstPageTitle)
                for misspellingCategoryTitle in categories)
        elif mylang in self.misspellingTemplate:
            templates = self.misspellingTemplate[mylang]
            if isinstance(templates, basestring):
                templates = (templates, )
            generators = (
                pagegenerators.ReferringPageGenerator(
                    pywikibot.Page(self.site, misspellingTemplateName, ns=10),
                    onlyTemplateInclusion=True)
                for misspellingTemplateName in templates)
            if firstPageTitle:
                pywikibot.output(
                    u'-start parameter unsupported on this wiki because there '
                    u'is no category for misspellings.')
        else:
            pywikibot.output(HELP_MSG.format(site=self.site))

            empty_gen = (i for i in [])
            return empty_gen
        generator = pagegenerators.CombinedPageGenerator(generators)
        preloadingGen = pagegenerators.PreloadingGenerator(generator)
        return preloadingGen
Example #6
0
def main(*args):
    templateNames = []
    templates = {}
    subst = False
    remove = False
    namespaces = []
    editSummary = ''
    addedCat = ''
    acceptAll = False
    genFactory = pagegenerators.GeneratorFactory()
    # If xmlfilename is None, references will be loaded from the live wiki.
    xmlfilename = None
    user = None
    skip = False
    timestamp = None
    # read command line parameters
    for arg in pywikibot.handleArgs(*args):
        if arg == '-remove':
            remove = True
        elif arg == '-subst':
            subst = True
        elif arg == '-assubst':
            subst = remove = True
        elif arg == ('-always'):
            acceptAll = True
        elif arg.startswith('-xml'):
            if len(arg) == 4:
                xmlfilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename: ')
            else:
                xmlfilename = arg[5:]
        elif arg.startswith('-category:'):
            addedCat = arg[len('-category:'):]
        elif arg.startswith('-summary:'):
            editSummary = arg[len('-summary:'):]
        elif arg.startswith('-user:'******'-user:'******'-skipuser:'******'-skipuser:'******'-timestamp:'):
            timestamp = arg[len('-timestamp:'):]
        else:
            if not genFactory.handleArg(arg):
                templateNames.append(
                    pywikibot.Page(pywikibot.Site(), arg,
                                   ns=10).title(withNamespace=False))

    if subst ^ remove:
        for templateName in templateNames:
            templates[templateName] = None
    else:
        try:
            for i in range(0, len(templateNames), 2):
                templates[templateNames[i]] = templateNames[i + 1]
        except IndexError:
            pywikibot.output(
                u'Unless using solely -subst or -remove, you must give an even number of template names.'
            )
            return

    oldTemplates = []
    ns = pywikibot.Site().template_namespace()
    for templateName in templates.keys():
        oldTemplate = pywikibot.Page(pywikibot.Site(), templateName, ns=10)
        oldTemplates.append(oldTemplate)

    if xmlfilename:
        gen = XmlDumpTemplatePageGenerator(oldTemplates, xmlfilename)
    else:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        gens = []
        gens = [
            pagegenerators.ReferringPageGenerator(t,
                                                  onlyTemplateInclusion=True)
            for t in oldTemplates
        ]
        gen = pagegenerators.CombinedPageGenerator(gens)
        gen = pagegenerators.DuplicateFilterPageGenerator(gen)

    if user:
        gen = UserEditFilterGenerator(gen, user, timestamp, skip)
    preloadingGen = pagegenerators.PreloadingGenerator(gen)

    bot = TemplateRobot(preloadingGen, templates, subst, remove, editSummary,
                        acceptAll, addedCat)
    bot.run()
Example #7
0
def main(*args):
    """
    Process command line arguments and invoke bot.

    If args is an empty list, sys.argv is used.

    @param args: command line arguments
    @type args: list of unicode
    """
    templateNames = []
    templates = {}
    options = {}
    # If xmlfilename is None, references will be loaded from the live wiki.
    xmlfilename = None
    user = None
    skip = False
    timestamp = None

    # read command line parameters
    local_args = pywikibot.handle_args(args)
    genFactory = pagegenerators.GeneratorFactory()
    for arg in local_args:
        if arg == '-remove':
            options['remove'] = True
        elif arg == '-subst':
            options['subst'] = True
        elif arg == '-assubst':
            options['subst'] = options['remove'] = True
        elif arg == '-always':
            options['always'] = True
        elif arg.startswith('-xml'):
            if len(arg) == 4:
                xmlfilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename: ')
            else:
                xmlfilename = arg[5:]
        elif arg.startswith('-category:'):
            options['addedCat'] = arg[len('-category:'):]
        elif arg.startswith('-summary:'):
            options['summary'] = arg[len('-summary:'):]
        elif arg.startswith('-user:'******'-user:'******'-skipuser:'******'-skipuser:'******'-timestamp:'):
            timestamp = arg[len('-timestamp:'):]
        else:
            if not genFactory.handleArg(arg):
                templateNames.append(
                    pywikibot.Page(pywikibot.Site(), arg,
                                   ns=10).title(withNamespace=False))

    if not templateNames:
        pywikibot.showHelp()
        return

    if options.get('subst', False) ^ options.get('remove', False):
        for templateName in templateNames:
            templates[templateName] = None
    else:
        try:
            for i in range(0, len(templateNames), 2):
                templates[templateNames[i]] = templateNames[i + 1]
        except IndexError:
            pywikibot.output(
                u'Unless using solely -subst or -remove, you must give an even number of template names.'
            )
            return

    oldTemplates = []
    for templateName in templates.keys():
        oldTemplate = pywikibot.Page(pywikibot.Site(), templateName, ns=10)
        oldTemplates.append(oldTemplate)

    if xmlfilename:
        gen = XmlDumpTemplatePageGenerator(oldTemplates, xmlfilename)
    else:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        gens = [
            pagegenerators.ReferringPageGenerator(t,
                                                  onlyTemplateInclusion=True)
            for t in oldTemplates
        ]
        gen = pagegenerators.CombinedPageGenerator(gens)
        gen = pagegenerators.DuplicateFilterPageGenerator(gen)
    if user:
        gen = UserEditFilterGenerator(gen,
                                      user,
                                      timestamp,
                                      skip,
                                      max_revision_depth=100)

    if not genFactory.gens:
        # make sure that proper namespace filtering etc. is handled
        gen = genFactory.getCombinedGenerator(gen)

    preloadingGen = pagegenerators.PreloadingGenerator(gen)

    bot = TemplateRobot(preloadingGen, templates, **options)
    bot.run()
Example #8
0
def main(*args):
    """
    Process command line arguments and invoke bot.

    If args is an empty list, sys.argv is used.

    @param args: command line arguments
    @type args: list of unicode
    """
    templateNames = []
    templates = {}
    options = {}
    # If xmlfilename is None, references will be loaded from the live wiki.
    xmlfilename = None
    user = None
    skip = False
    timestamp = None

    # read command line parameters
    local_args = pywikibot.handle_args(args)

    # Avoid conflicts with pagegenerators.py parameters.
    if any(arg.startswith('-category:') for arg in local_args):
        warn(
            '-category (to append a category to each edited page) has been'
            ' renamed to -addcat; make sure you are using the correct param.',
            ArgumentDeprecationWarning)

    site = pywikibot.Site()
    genFactory = pagegenerators.GeneratorFactory()
    for arg in local_args:
        if arg == '-remove':
            options['remove'] = True
        elif arg == '-subst':
            options['subst'] = True
        elif arg == '-assubst':
            options['subst'] = options['remove'] = True
        elif arg == '-always':
            options['always'] = True
        elif arg.startswith('-xml'):
            if len(arg) == 4:
                xmlfilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename: ')
            else:
                xmlfilename = arg[5:]
        elif arg.startswith('-addcat:'):
            options['addedCat'] = arg[len('-addcat:'):]
        elif arg.startswith('-summary:'):
            options['summary'] = arg[len('-summary:'):]
        elif arg.startswith('-onlyuser:'******'-onlyuser:'******'-skipuser:'******'-skipuser:'******'-timestamp:'):
            timestamp = arg[len('-timestamp:'):]
        else:
            if not genFactory.handleArg(arg):
                templateName = pywikibot.Page(site, arg, ns=10)
                templateNames.append(templateName.title(withNamespace=False))

    if not templateNames:
        pywikibot.bot.suggest_help(missing_parameters=['templates'])
        return False

    if options.get('subst', False) ^ options.get('remove', False):
        for templateName in templateNames:
            templates[templateName] = None
    else:
        try:
            for i in range(0, len(templateNames), 2):
                templates[templateNames[i]] = templateNames[i + 1]
        except IndexError:
            pywikibot.output('Unless using solely -subst or -remove, '
                             'you must give an even number of template names.')
            return

    oldTemplates = []
    for templateName in templates.keys():
        oldTemplate = pywikibot.Page(site, templateName, ns=10)
        oldTemplates.append(oldTemplate)

    if xmlfilename:
        builder = textlib._MultiTemplateMatchBuilder(site)
        predicate = builder.search_any_predicate(oldTemplates)

        gen = XmlDumpTemplatePageGenerator(xmlfilename,
                                           site=site,
                                           text_predicate=predicate)
    else:
        gen = genFactory.getCombinedGenerator()

    if not gen:
        gens = [
            pagegenerators.ReferringPageGenerator(t,
                                                  onlyTemplateInclusion=True)
            for t in oldTemplates
        ]
        gen = pagegenerators.CombinedPageGenerator(gens)
        gen = pagegenerators.DuplicateFilterPageGenerator(gen)
    if user:
        gen = pagegenerators.UserEditFilterGenerator(gen,
                                                     user,
                                                     timestamp,
                                                     skip,
                                                     max_revision_depth=100,
                                                     show_filtered=True)

    if not genFactory.gens:
        # make sure that proper namespace filtering etc. is handled
        gen = genFactory.getCombinedGenerator(gen)

    preloadingGen = pagegenerators.PreloadingGenerator(gen)

    bot = TemplateRobot(preloadingGen, templates, **options)
    bot.run()
mail.set_charset('utf-8')
mail['From'] = mailFrom
mail['To'] = mailRcpt
mail['Subject'] = Header(mailSubj.encode('utf-8'), 'utf-8')

adminReqPagesPrevYear = pagegenerators.PrefixingPageGenerator(
    'Заявки към администраторите/' + str(currentDateTime.year - 1),
    namespace='Уикипедия',
    includeredirects=False)

adminReqPagesCurrYear = pagegenerators.PrefixingPageGenerator(
    'Заявки към администраторите/' + str(currentDateTime.year),
    namespace='Уикипедия',
    includeredirects=False)

adminReqPages = pagegenerators.CombinedPageGenerator(
    [adminReqPagesPrevYear, adminReqPagesCurrYear])

adminReqPagesRecent = pagegenerators.EdittimeFilterPageGenerator(
    adminReqPages, last_edit_start=lastDateTime)

revisionCount = 0
for reqPage in adminReqPagesRecent:
    mailBody += '##############################################################################\n\n'
    mailBody += 'https://bg.wikipedia.org/wiki/' + reqPage.title().replace(
        ' ', '_') + '\n\n'
    mailBody += '##############################################################################\n\n'
    for revision in reqPage.revisions(reverse=True,
                                      starttime=lastDateTime,
                                      content=True):
        revisionCount += 1
        mailBody += 'Дата и час: %s' % revision.timestamp + '\n'