示例#1
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: unicode
    """
    options = {}
    total = None

    local_args = pywikibot.handle_args(args)

    for arg in local_args:
        arg, sep, value = arg.partition(':')
        if arg == '-total':
            total = value
        else:
            options[arg[1:]] = True

    site = pywikibot.Site()
    gen = pagegenerators.UnusedFilesGenerator(total=total, site=site)
    gen = pagegenerators.PreloadingGenerator(gen)

    bot = UnusedFilesBot(site=site, generator=gen, **options)
    try:
        bot.run()
    except pywikibot.Error as e:
        pywikibot.bot.suggest_help(exception=e)
        return False
    else:
        return True
示例#2
0
 def run(self):
     template_image = i18n.translate(self.site, template_to_the_image)
     template_user = i18n.translate(self.site, template_to_the_user)
     except_text_translated = i18n.translate(self.site, except_text)
     summary = i18n.translate(self.site, comment, fallback=True)
     if not all(
         [template_image, template_user, except_text_translated, comment]):
         raise pywikibot.Error(
             u'This script is not localized for %s site.' % self.site)
     self.summary = summary
     generator = pagegenerators.UnusedFilesGenerator(site=self.site)
     generator = pagegenerators.PreloadingGenerator(generator)
     for image in generator:
         if not image.exists():
             pywikibot.output(u"File '%s' does not exist (see bug 69133)." %
                              image.title())
             continue
         if (except_text_translated.encode('utf-8')
                 not in image.getImagePageHtml()
                 and u'http://' not in image.text):
             if template_image in image.text:
                 pywikibot.output(u"%s done already" %
                                  image.title(asLink=True))
                 continue
             self.append_text(image, u"\n\n" + template_image)
             uploader = image.getFileVersionHistory().pop(0)['user']
             user = pywikibot.User(image.site, uploader)
             usertalkpage = user.getUserTalkPage()
             msg2uploader = template_user % {'title': image.title()}
             self.append_text(usertalkpage, msg2uploader)
示例#3
0
def main():
    always = False

    for arg in pywikibot.handleArgs():
        if arg == '-always':
            always = True

    mysite = pywikibot.Site()
    # If anything needs to be prepared, you can do it here
    template_image = i18n.translate(pywikibot.Site(), template_to_the_image)
    template_user = i18n.translate(pywikibot.Site(), template_to_the_user)
    except_text_translated = i18n.translate(pywikibot.Site(), except_text)
    if not (template_image and template_user and except_text_translated):
        pywikibot.warning(u'This script is not localized for %s site.' %
                          mysite)
        return
    generator = pagegenerators.UnusedFilesGenerator()
    generator = pagegenerators.PreloadingGenerator(generator)
    for image in generator:
        if (except_text_translated.encode('utf-8')
                not in image.getImagePageHtml()
                and u'http://' not in image.text):
            pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                             image.title())
            if template_image in image.text:
                pywikibot.output(u"%s done already" % image.title(asLink=True))
                continue
            appendtext(image, u"\n\n" + template_image, always)
            uploader = image.getFileVersionHistory().pop(0)['user']
            user = pywikibot.User(mysite, uploader)
            usertalkpage = user.getUserTalkPage()
            msg2uploader = template_user % {'title': image.title()}
            appendtext(usertalkpage, msg2uploader, always)
示例#4
0
 def run(self):
     """Start the bot."""
     template_image = i18n.translate(self.site,
                                     template_to_the_image)
     template_user = i18n.translate(self.site,
                                    template_to_the_user)
     summary = i18n.translate(self.site, comment, fallback=True)
     if not all([template_image, template_user, comment]):
         raise pywikibot.Error(u'This script is not localized for %s site.'
                               % self.site)
     self.summary = summary
     generator = pagegenerators.UnusedFilesGenerator(site=self.site)
     generator = pagegenerators.PreloadingGenerator(generator)
     for image in generator:
         if not image.exists():
             pywikibot.output(u"File '%s' does not exist (see bug 69133)."
                              % image.title())
             continue
         # Use fileUrl() and fileIsShared() to confirm it is local media
         # rather than a local page with the same name as shared media.
         if (image.fileUrl() and not image.fileIsShared() and
                 u'http://' not in image.text):
             if template_image in image.text:
                 pywikibot.output(u"%s done already"
                                  % image.title(asLink=True))
                 continue
             self.append_text(image, u"\n\n" + template_image)
             uploader = image.getFileVersionHistory().pop(0)['user']
             user = pywikibot.User(image.site, uploader)
             usertalkpage = user.getUserTalkPage()
             msg2uploader = template_user % {'title': image.title()}
             self.append_text(usertalkpage, msg2uploader)
示例#5
0
 def run(self):
     template_image = i18n.translate(self.site, template_to_the_image)
     template_user = i18n.translate(self.site, template_to_the_user)
     except_text_translated = i18n.translate(self.site, except_text)
     summary = i18n.translate(self.site, comment, fallback=True)
     if not all(
         [template_image, template_user, except_text_translated, comment]):
         raise pywikibot.Error(
             u'This script is not localized for %s site.' % self.site)
     self.summary = summary
     generator = pagegenerators.UnusedFilesGenerator(total=1000,
                                                     site=self.site)  #500
     generator = pagegenerators.PreloadingGenerator(generator)
     for image in generator:
         tituloImagem = image.title()
         if not image.exists():
             pywikibot.output(u"File '%s' does not exist (see bug 69133)." %
                              image.title())
             continue
         print(tituloImagem)
         imagemTexto = image.text
         if (except_text_translated not in image.getImagePageHtml()
                 and u'http://' not in imagemTexto):
             if template_image in image.text:
                 pywikibot.output(u"%s done already" %
                                  image.title(asLink=True))
                 continue
             #self.append_text(image, u"\n\n" + template_image)
             categorias = list(image.categories())
             if not categorias:
                 print(tituloImagem + " deletado")
                 image.delete(u"Imagem não utilizada", False, True)
             else:
                 print("Há categorias!\nPulando " + tituloImagem)
             '''uploader = image.getFileVersionHistory().pop(0)['user']
示例#6
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: str
    """
    options = {}
    total = None

    local_args = pywikibot.handle_args(args)

    for arg in local_args:
        arg, sep, value = arg.partition(':')
        if arg == '-limit':
            total = value
        elif arg == '-total':
            total = value
            issue_deprecation_warning('The usage of "{0}"'.format(arg),
                                      '-limit',
                                      2,
                                      ArgumentDeprecationWarning,
                                      since='20190120')
        else:
            options[arg[1:]] = True

    site = pywikibot.Site()
    gen = pagegenerators.UnusedFilesGenerator(total=total, site=site)
    gen = pagegenerators.PreloadingGenerator(gen)

    bot = UnusedFilesBot(site=site, generator=gen, **options)
    try:
        bot.run()
    except pywikibot.Error as e:
        pywikibot.bot.suggest_help(exception=e)
        return False
    else:
        return True