def main():
    '''
    The main loop
    '''
    wikipedia.handleArgs()
    conn = None
    cursor = None
    (conn, cursor) = connectDatabase()
    for templateTitle in getUncategorizedTemplates(cursor):
        tagUncategorized(templateTitle)
Пример #2
0
def main():
    '''
    The main loop
    '''
    wikipedia.handleArgs()
    conn = None
    cursor = None
    (conn, cursor) = connectDatabase()
    imageList = getImagesToNowcommons(cursor)
    for (wImage, cImage, timestamp) in imageList:
	tagNowCommons(unicode(wImage, 'utf-8'), unicode(cImage, 'utf-8'), timestamp)
def main():
    '''
    The main loop
    '''
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
    conn = None
    cursor = None
    (conn, cursor) = connectDatabase()

    imagerecat.initLists()
    generator = None;
    genFactory = pagegenerators.GeneratorFactory()

    mark = True

    for arg in wikipedia.handleArgs():
	if arg.startswith('-dontmark'):
	    mark = False
        elif arg.startswith('-page'):
            if len(arg) == 5:
                generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
            else:
                generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
	elif arg.startswith('-yesterday'):
	    generator = [wikipedia.Page(wikipedia.getSite(), u'Category:Media_needing_categories_as_of_' + getYesterday())]
        else:
            generator = genFactory.handleArg(arg)
    if generator:
        for page in generator:
	    if((page.namespace() == 14) and (page.title().startswith(u'Category:Media needing categories as of'))):
		wikipedia.output(u'Working on ' + page.title())
		for (image, gals, cats) in getImagesToCategorize(cursor, page.titleWithoutNamespace()):
		    categorizeImage(image, gals, imagerecat.applyAllFilters(cats))
		if (mark):
		    categoriesChecked(page.title())
Пример #4
0
def main():
    operation = None
    argsList = []
    namespaces = []

    for arg in wikipedia.handleArgs():
        if arg == '-count':
            operation = "Count"
        elif arg == '-list':
            operation = "List"
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[len('-namespace:'):]))
            except ValueError:
                namespaces.append(arg[len('-namespace:'):])
        else:
            argsList.append(arg)

    if operation == None:
        wikipedia.showHelp('templatecount')
    else:
        robot = TemplateCountRobot()
        if not argsList:
            argsList = ['ref', 'note', 'ref label', 'note label']
        if operation == "Count":
            robot.countTemplates(argsList, namespaces)
        elif operation == "List":
            robot.listTemplates(argsList, namespaces)
Пример #5
0
def main(args):
    '''
    Grab a bunch of images and tag them if they are not categorized.
    '''
    generator = None
    genFactory = pagegenerators.GeneratorFactory()

    site = pywikibot.getSite(u'commons', u'commons')
    pywikibot.setSite(site)
    for arg in pywikibot.handleArgs():
        if arg.startswith('-yesterday'):
            generator = uploadedYesterday(site)
        elif arg.startswith('-recentchanges'):
            generator = recentChanges(site=site, delay=120)
        else:
            genFactory.handleArg(arg)
    if not generator:
        generator = genFactory.getCombinedGenerator()
    if not generator:
        pywikibot.output(
          u'You have to specify the generator you want to use for the program!')
    else:
        pregenerator = pagegenerators.PreloadingGenerator(generator)
        for page in pregenerator:
            if page.exists() and (page.namespace() == 6) \
                   and (not page.isRedirectPage()) :
                if isUncat(page):
                    addUncat(page)
Пример #6
0
def main():
    '''
    The main loop
    '''
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
    conn = None
    cursor = None
    uncat = u''
    (conn, cursor) = connectDatabase()

    for arg in wikipedia.handleArgs():
        if arg.startswith('-date'):
            if len(arg) == 5:
                uncat = u'Media_needing_categories_as_of_' + wikipedia.input(
                    u'What page do you want to use?')
            else:
                uncat = u'Media_needing_categories_as_of_' + arg[6:]
        elif arg.startswith('-yesterday'):
            uncat = u'Media_needing_categories_as_of_' + getYesterday()
    if uncat:
        uncat = uncat.replace(' ', '_')
        for (user, images) in getUsersToNotify(cursor, uncat):
            notifyUser(user, images, uncat)
    else:
        wikipedia.output(u'Please specify date to work with "-date:' +
                         getYesterday() + u'" or "-yesterday"')
Пример #7
0
def main():
    always = False
    for arg in wikipedia.handleArgs():
        if arg == '-always':
            always = True

    mysite = wikipedia.getSite()
    # If anything needs to be prepared, you can do it here
    template_image = wikipedia.translate(wikipedia.getSite(),
                                         template_to_the_image)
    template_user = wikipedia.translate(wikipedia.getSite(),
                                        template_to_the_user)
    except_text_translated = wikipedia.translate(wikipedia.getSite(),
                                                 except_text)
    basicgenerator = pagegenerators.UnusedFilesGenerator()
    generator = pagegenerators.PreloadingGenerator(basicgenerator)
    for page in generator:
        wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                         page.title())
        if except_text_translated not in page.getImagePageHtml(
        ) and 'http://' not in page.get():
            wikipedia.output(u'\n' + page.title())
            appendtext(page, template_image, always)
            uploader = page.getFileVersionHistory().pop()[1]
            usertalkname = u'User Talk:%s' % uploader
            usertalkpage = wikipedia.Page(mysite, usertalkname)
            msg2uploader = template_user % page.title()
            appendtext(usertalkpage, msg2uploader, always)
Пример #8
0
def main(args):
    '''
    Main loop. Get a generator and options.
    '''
    generator = None
    parent = u''
    basename = u''
    always = False

    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == '-always':
            always = True
        elif arg.startswith('-parent:'):
            parent = arg [len('-parent:'):].strip()
        elif arg.startswith('-basename'):
            basename = arg [len('-basename:'):].strip()
        else:
            genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()
    if generator:
        for page in generator:
            createCategory(page, parent, basename)
    else:
        pywikibot.output(u'No pages to work on')

    pywikibot.output(u'All done')
Пример #9
0
def main():
    #page generator
    gen = None
    # This temporary array is used to read the page title if one single
    # page to work on is specified by the arguments.
    pageTitle = []
    # Which namespaces should be processed?
    # default to [] which means all namespaces will be processed
    namespaces = []
    # Never ask before changing a page
    always = False
    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg.startswith('-xml'):
            if len(arg) == 4:
                xmlFilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename:')
            else:
                xmlFilename = arg[5:]
            gen = XmlDumpNoReferencesPageGenerator(xmlFilename)
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[11:]))
            except ValueError:
                namespaces.append(arg[11:])
        elif arg == '-always':
            always = True
        else:
            if not genFactory.handleArg(arg):
                pageTitle.append(arg)

    if pageTitle:
        page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
        gen = iter([page])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        site = pywikibot.getSite()
        try:
            cat = maintenance_category[site.family.name][site.lang]
        except:
            pass
        else:
            import catlib
            if not namespaces:
                namespaces = [0]
            cat = catlib.Category(site, "%s:%s" % (site.namespace(14), cat))
            gen = pagegenerators.CategorizedPageGenerator(cat)
    if not gen:
        pywikibot.showHelp('noreferences')
    else:
        if namespaces:
            gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = NoReferencesBot(preloadingGen, always)
        bot.run()
Пример #10
0
    def set_options(self, *args):
        """Parse commandline and set options attribute"""
        my_args = []
        for arg in pywikibot.handleArgs(*args):
            my_args.append(arg)
        parser = optparse.OptionParser()
        parser.add_option("-r",
                          "--edit_redirect",
                          action="store_true",
                          default=False,
                          help="Ignore/edit redirects")
        parser.add_option("-p", "--page", help="Page to edit")
        parser.add_option("-w",
                          "--watch",
                          action="store_true",
                          default=False,
                          help="Watch article after edit")
        #parser.add_option("-n", "--new_data", default="",
        #                  help="Automatically generated content")
        (self.options, args) = parser.parse_args(args=my_args)

        # for convenience, if we have an arg, stuff it into the opt, so we
        # can act like a normal editor.
        if (len(args) == 1):
            self.options.page = args[0]
Пример #11
0
def main():
    # If debug is True, don't edit pages, but only show what would have been
    # changed.
    debug = False
    # The AfD log that should be treated.
    date = None
    # Whether to confirm edits.
    always = False

    # Parse command line arguments
    for arg in wikipedia.handleArgs():
        if arg.startswith('-debug'):
            wikipedia.output(u'Debug mode.')
            debug = True
        elif arg.startswith('-date'):
            if len(arg) == 5:
                date = wikipedia.input(
                    u'Please enter the date of the log that should be treated (yyyymmdd):'
                )
            else:
                date = arg[6:]
        elif arg.startswith('-always'):
            always = True

    if date:
        page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % date
    else:
        page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % time.strftime(
            "%Y%m%d", time.localtime(time.time() - 60 * 60 * 24))

    wikipedia.output(u'Checking: %s.' % page_title)
    page = wikipedia.Page(wikipedia.getSite(code='nl', fam='wikipedia'),
                          page_title)
    bot = AfDBot(page, always, debug)
    bot.run()
def main():
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))

    # Connect database, we need that
    conn = None
    cursor = None
    (conn, cursor) = connectDatabase()

    generator = None
    genFactory = pagegenerators.GeneratorFactory()

    for arg in wikipedia.handleArgs():
        genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()

    if not generator:
        generator = getRijksmonumentWithoutLocation()

    # Get a preloading generator with only images
    pgenerator = pagegenerators.PreloadingGenerator(
        pagegenerators.NamespaceFilterPageGenerator(generator, [6]))
    for page in pgenerator:
        locationTemplate = locateImage(page, conn, cursor)
        if locationTemplate:
            addLocation(page, locationTemplate)
Пример #13
0
def main(args):
    '''
    Main loop. Get a generator and options. Work on all images in the generator.
    '''
    generator = None
    onlyFilter = False
    onlyUncat = False
    genFactory = pagegenerators.GeneratorFactory()

    global search_wikis
    global hint_wiki

    site = pywikibot.getSite(u'commons', u'commons')
    pywikibot.setSite(site)
    for arg in pywikibot.handleArgs():
        if arg == '-onlyfilter':
            onlyFilter = True
        elif arg == '-onlyuncat':
            onlyUncat = True
        elif arg.startswith('-hint:'):
            hint_wiki = arg[len('-hint:'):]
        elif arg.startswith('-onlyhint'):
            search_wikis = arg[len('-onlyhint:'):]
        else:
            genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()
    if not generator:
        generator = pagegenerators.CategorizedPageGenerator(catlib.Category(
            site, u'Category:Media needing categories'),
                                                            recurse=True)
    initLists()
    categorizeImages(generator, onlyFilter, onlyUncat)
    pywikibot.output(u'All done')
Пример #14
0
def main():
    #page generator
    gen = None
    # If the user chooses to work on a single page, this temporary array is
    # used to read the words from the page title. The words will later be
    # joined with spaces to retrieve the full title.
    pageTitle = []
    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()

    for arg in wikipedia.handleArgs():
        if not genFactory.handleArg(arg):
            pageTitle.append(arg)

    if pageTitle:
        # work on a single page
        page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
        gen = iter([page])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        wikipedia.showHelp('inline_images')
    else:
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = InlineImagesRobot(preloadingGen)
        bot.run()
Пример #15
0
def main():
    genFactory = pagegenerators.GeneratorFactory()
    # The generator gives the pages that should be worked upon.
    gen = None
    pageTitleParts = []

    for arg in pywikibot.handleArgs():
        if arg.startswith("-reg"):
            arg = '-transcludes:Infobox film'
        if not genFactory.handleArg(arg):
            pageTitleParts.append(arg)

    if pageTitleParts != []:
        # We will only work on a single page.
        pageTitle = ' '.join(pageTitleParts)
        page = pywikibot.Page(pywikibot.getSite(), pageTitle)
        gen = iter([page])

    if not gen:
        gen = genFactory.getCombinedGenerator()
    if gen:
        # The preloading generator is responsible for downloading multiple
        # pages from the wiki simultaneously.
        gen = pagegenerators.PreloadingGenerator(gen)
        bot = FilmBannerBot(gen)
        bot.run()
    else:
        pywikibot.showHelp()
Пример #16
0
def main(*args):
    try:
        genFactory = pagegenerators.GeneratorFactory()
        for arg in pywikibot.handleArgs(*args):
            if not genFactory.handleArg(arg):
                pywikibot.showHelp()
                break
        else:
            gen = genFactory.getCombinedGenerator()
            if gen:
                page_match = re.compile('\{\{AFC submission\|')
                summary = u"[[User:HasteurBot|HasteurBot Task 3]]: Removing " + \
                  u"maint category that does not apply"
                disclude_list = [
                    u'Wikipedia talk:WikiProject Articles for creation',
                    u'Wikipedia talk:WikiProject Articles for creation/2013 5',
                    u'Wikipedia talk:WikiProject Articles for creation/2011',
                ]
                for article in gen:
                    if article.title() in disclude_list:
                        continue
                    art_text = article.get()
                    if page_match.match(art_text) is not None:
                        print article
                        art_1 = re.sub(
                            '\\\n\[\[\:Category\:AfC_submissions_with_missing_AfC_template\]\]',
                            '', art_text)
                        art_2 = re.sub(
                            '\\\n\[\[\:Category\:AfC submissions with missing AfC template\]\]',
                            '', art_1)
                        article.put(art_2, comment=summary)
            else:
                pywikibot.showHelp()
    finally:
        pywikibot.stopme()
Пример #17
0
def main():
    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()
    # The generator gives the pages that should be worked upon.
    gen = None
    # This temporary array is used to read the page title if one single
    # page to work on is specified by the arguments.
    pageTitleParts = []

    # Parse command line arguments
    for arg in pywikibot.handleArgs():
        if arg.startswith("-reg"):
            arg = '-cat:Unassessed film articles'
        if not genFactory.handleArg(arg):
            pageTitleParts.append(arg)

    if pageTitleParts != []:
        # We will only work on a single page.
        pageTitle = ' '.join(pageTitleParts)
        page = pywikibot.Page(pywikibot.getSite(), pageTitle)
        gen = iter([page])

    if not gen:
        gen = genFactory.getCombinedGenerator()
    if gen:
        # The preloading generator is responsible for downloading multiple
        # pages from the wiki simultaneously.
        gen = pagegenerators.PreloadingGenerator(
            filmfunctions.PagesFromTalkPagesGenerator(gen))
        bot = FilmAssessBot(gen)
        bot.run()
    else:
        pywikibot.showHelp()
Пример #18
0
def main():
    # read command line parameters
    for arg in pywikibot.handleArgs():
        pass  #No args yet

    bot = SpeedyRobot()
    bot.run()
Пример #19
0
def main(args):
    '''
    Grab a bunch of images and tag them if they are not categorized.
    '''
    generator = None
    genFactory = pagegenerators.GeneratorFactory()

    site = pywikibot.getSite(u'commons', u'commons')
    pywikibot.setSite(site)
    for arg in pywikibot.handleArgs():
        if arg.startswith('-yesterday'):
            generator = uploadedYesterday(site)
        elif arg.startswith('-recentchanges'):
            generator = recentChanges(site=site, delay=120)
        else:
            genFactory.handleArg(arg)
    if not generator:
        generator = genFactory.getCombinedGenerator()
    if not generator:
        pywikibot.output(
          u'You have to specify the generator you want to use for the program!')
    else:
        pregenerator = pagegenerators.PreloadingGenerator(generator)
        for page in pregenerator:
            if page.exists() and (page.namespace() == 6) \
                   and (not page.isRedirectPage()) :
                if isUncat(page):
                    addUncat(page)
Пример #20
0
def main():
    global always
    always = False

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

    mysite = pywikibot.getSite()
    # If anything needs to be prepared, you can do it here
    template_image = pywikibot.translate(pywikibot.getSite(),
                                         template_to_the_image)
    template_user = pywikibot.translate(pywikibot.getSite(),
                                        template_to_the_user)
    except_text_translated = pywikibot.translate(pywikibot.getSite(),
                                                 except_text)
    basicgenerator = pagegenerators.UnusedFilesGenerator()
    generator = pagegenerators.PreloadingGenerator(basicgenerator)
    for page in generator:
        pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                         page.title())
        if except_text_translated not in page.getImagePageHtml() and \
                not re.search("https?\:\/\/", page.get()):
            pywikibot.output(u'\n' + page.title())
            if template_image in page.get():
                pywikibot.output(u"%s done already" % page.title(asLink=True))
                continue
            appendtext(page, u"\n\n" + template_image)
            uploader = page.getFileVersionHistory().pop()[1]
            usertalkname = u'User Talk:%s' % uploader
            usertalkpage = pywikibot.Page(mysite, usertalkname)
            msg2uploader = template_user % {'title': page.title()}
            appendtext(usertalkpage, msg2uploader)
Пример #21
0
def main(args):
    '''
    Main loop. Get a generator and options.
    '''
    generator = None
    parent = u''
    basename = u''
    always = False

    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == '-always':
            always = True
        elif arg.startswith('-parent:'):
            parent = arg [len('-parent:'):].strip()
        elif arg.startswith('-basename'):
            basename = arg [len('-basename:'):].strip()
        else:
            genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()
    if generator:
        for page in generator:
            createCategory(page, parent, basename)
    else:
        pywikibot.output(u'No pages to work on')

    pywikibot.output(u'All done')
Пример #22
0
def main(*args):
    # Disable cosmetic changes because we don't want to modify any page
    # content, so that we don't flood the histories with minor changes.
    config.cosmetic_changes = False
    #page generator
    gen = None
    genFactory = pagegenerators.GeneratorFactory()
    redirs = False
    # If the user chooses to work on a single page, this temporary array is
    # used to read the words from the page title. The words will later be
    # joined with spaces to retrieve the full title.
    pageTitle = []
    for arg in pywikibot.handleArgs(*args):
        if genFactory.handleArg(arg):
            continue
        if arg == '-redir':
            redirs = True
        else:
            pageTitle.append(arg)

    gen = genFactory.getCombinedGenerator()
    if not gen:
        if pageTitle:
            # work on a single page
            page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
            gen = iter([page])
        else:
            pywikibot.showHelp()
            return
    preloadingGen = pagegenerators.PreloadingGenerator(gen)
    bot = TouchBot(preloadingGen, redirs)
    bot.run()
def main():
    # The generator gives the pages that should be worked upon.
    gen = None
    # If debug is True, doesn't do any real changes, but only show
    # what would have been changed.
    debug = False
    wantHelp = False

    cat = catlib.Category(wikipedia.getSite(), 'Category:%s' % 'Instance')
    gen = pagegenerators.CategorizedPageGenerator(cat,
                                                  start=None,
                                                  recurse=False)

    # Parse command line arguments
    for arg in wikipedia.handleArgs():
        if arg.startswith("-debug"):
            debug = True
        else:
            print arg, "yielding wanthelp"
            wantHelp = True

    if not wantHelp:
        # The preloading generator is responsible for downloading multiple
        # pages from the wiki simultaneously.
        gen = pagegenerators.PreloadingGenerator(gen)
        bot = PuppetUnmanagedListBot(gen, debug)
        bot.run()
    else:
        wikipedia.showHelp()
Пример #24
0
def main(*args):
    url = u''
    description = []
    keepFilename = False
    useFilename = None
    verifyDescription = True

    # process all global bot args
    # returns a list of non-global args, i.e. args for upload.py
    for arg in pywikibot.handleArgs(*args):
        if arg:
            if arg.startswith('-keep'):
                keepFilename = True
            elif arg.startswith('-filename:'):
                useFilename = arg[10:]
            elif arg.startswith('-noverify'):
                verifyDescription = False
            elif url == u'':
                url = arg
            else:
                description.append(arg)
    description = u' '.join(description)
    bot = UploadRobot(url,
                      description=description,
                      useFilename=useFilename,
                      keepFilename=keepFilename,
                      verifyDescription=verifyDescription)
    bot.run()
Пример #25
0
def main():
    featured = False
    gen = None

    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == '-featured':
            featured = True
        else:
            genFactory.handleArg(arg)

    mysite = pywikibot.getSite()
    if mysite.sitename() == 'wikipedia:nl':
        pywikibot.output(
            u'\03{lightred}There is consensus on the Dutch Wikipedia that bots should not be used to fix redirects.\03{default}'
        )
        sys.exit()

    if featured:
        featuredList = pywikibot.translate(mysite, featured_articles)
        ref = pywikibot.Page(pywikibot.getSite(), featuredList)
        gen = pagegenerators.ReferringPageGenerator(ref)
        gen = pagegenerators.NamespaceFilterPageGenerator(gen, [0])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if gen:
        for page in pagegenerators.PreloadingGenerator(gen):
            workon(page)
    else:
        pywikibot.showHelp('fixing_redirects')
Пример #26
0
def main():
    genFactory = pg.GeneratorFactory()
    commandline_arguments = list()
    templateTitle = u''
    for arg in pywikibot.handleArgs():
        if arg.startswith('-template'):
            if len(arg) == 9:
                templateTitle = pywikibot.input(
                    u'Please enter the template to work on:')
            else:
                templateTitle = arg[10:]
        elif genFactory.handleArg(arg):
            continue
        else:
            commandline_arguments.append(arg)

    if len(commandline_arguments) % 2 or not templateTitle:
        raise ValueError  # or something.
    fields = dict()

    for i in xrange(0, len(commandline_arguments), 2):
        fields[commandline_arguments[i]] = commandline_arguments[i + 1]
    if templateTitle:
        gen = pg.ReferringPageGenerator(pywikibot.Page(
            pywikibot.getSite(), "Template:%s" % templateTitle),
                                        onlyTemplateInclusion=True)
    else:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        # TODO: Build a transcluding generator based on templateTitle
        return

    bot = HarvestRobot(gen, templateTitle, fields)
    bot.run()
Пример #27
0
def main(args):
    url = u""
    description = []
    keepFilename = False
    useFilename = None
    verifyDescription = True

    # call wikipedia.py function to process all global wikipedia args
    # returns a list of non-global args, i.e. args for upload.py
    args = wikipedia.handleArgs()

    for arg in args:
        if arg:
            if arg.startswith("-keep"):
                keepFilename = True
            elif arg.startswith("-filename:"):
                useFilename = arg[10:]
            elif arg.startswith("-noverify"):
                verifyDescription = False
            elif url == u"":
                url = arg
            else:
                description.append(arg)
    description = u" ".join(description)
    bot = UploadRobot(
        url,
        description=description,
        useFilename=useFilename,
        keepFilename=keepFilename,
        verifyDescription=verifyDescription,
    )
    bot.run()
Пример #28
0
def main():
    global mysite, linktrail, page
    start = []
    for arg in pywikibot.handleArgs():
        start.append(arg)
    if start:
        start = " ".join(start)
    else:
        start = "!"
    mysite = pywikibot.getSite()
    linktrail = mysite.linktrail()
    try:
        generator = pagegenerators.CategorizedPageGenerator(
            mysite.disambcategory(), start=start)
    except pywikibot.NoPage:
        pywikibot.output(
            "The bot does not know the disambiguation category for your wiki.")
        raise
    # only work on articles
    generator = pagegenerators.NamespaceFilterPageGenerator(generator, [0])
    generator = pagegenerators.PreloadingGenerator(generator)
    pagestodo = []
    pagestoload = []
    for page in generator:
        if page.isRedirectPage():
            continue
        linked = page.linkedPages()
        pagestodo.append((page, linked))
        pagestoload += linked
        if len(pagestoload) > 49:
            pywikibot.getall(mysite, pagestoload)
            for page, links in pagestodo:
                workon(page, links)
            pagestoload = []
            pagestodo = []
Пример #29
0
def main():
    bbox="20.2148438,43.7710938,29.7729492,48.1147666" #default to Romania
    summary=None
    lang=pywikibot.getSite().language()
    # Loading the arguments
    for arg in pywikibot.handleArgs():
        if arg.startswith('-bbox'):
            if len(arg) == 5:
                bbox = pywikibot.input(
                    u'Please input the area to search for tagged nodes:')
            else:
                bbox = arg[6:]
        elif arg.startswith('-summary'):
            if len(arg) == 8:
                summary = pywikibot.input(u'What summary do you want to use?')
            else:
                summary = arg[9:]
        elif arg.startswith('-lang'):
            if len(arg) == 5:
                lang = pywikibot.input(u'What language do you want to use?')
            else:
                lang = arg[6:]
        
    pages = getPageList(bbox, lang)
    putCoordOnWiki(lang, pages)
Пример #30
0
def main():
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))

    bigcategory = u''
    target = u''

    generator = None
    for arg in wikipedia.handleArgs():
        if arg.startswith('-page'):
            if len(arg) == 5:
	        generator = [wikipedia.Page(wikipedia.getSite(), wikipedia.input(u'What page do you want to use?'))]
	    else:
                generator = [wikipedia.Page(wikipedia.getSite(), arg[6:])]
	elif arg.startswith('-bigcat'):
	    if len(arg) == 7:
		bigcategory = wikipedia.input(u'What category do you want to split out?')
	    else:
    		bigcategory = arg[8:]
	elif arg.startswith('-target'):
	    if len(arg) == 7:
		target = wikipedia.input(u'What category is the target category?')
	    else:
		target = arg[8:]

    if not bigcategory==u'':
	splitOutCategory(bigcategory, target)
    else:
	if not generator:
	    generator = pagegenerators.NamespaceFilterPageGenerator(pagegenerators.ReferringPageGenerator(wikipedia.Page(wikipedia.getSite(), u'Template:Intersect categories'), onlyTemplateInclusion=True), [14])
	for cat in generator:
	    intersectCategories(cat)
def main():
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))

    # Connect database, we need that
    conn = None
    cursor = None
    (conn, cursor) = connectDatabase()

    generator = None
    genFactory = pagegenerators.GeneratorFactory()

    for arg in wikipedia.handleArgs():
	genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()

    if not generator:
	generator = getRijksmonumentWithoutLocation()
    
    # Get a preloading generator with only images
    pgenerator = pagegenerators.PreloadingGenerator(pagegenerators.NamespaceFilterPageGenerator(generator, [6]))
    for page in pgenerator:
	locationTemplate = locateImage(page, conn, cursor)
	if locationTemplate:
	    addLocation(page, locationTemplate)
Пример #32
0
def main():
    global autonomous
    global replace, replacealways, replaceloose, replaceonly
    global use_hash
    autonomous = False
    replace = False
    replacealways = False
    replaceloose = False
    replaceonly = False
    use_hash = False

    for arg in pywikibot.handleArgs():
        if arg == '-autonomous':
            autonomous = True
        if arg == '-replace':
            replace = True
        if arg == '-replacealways':
            replace = True
            replacealways = True
        if arg == '-replaceloose':
            replaceloose = True
        if arg == '-replaceonly':
            replaceonly = True
        if arg == '-hash':
            use_hash = True
    bot = NowCommonsDeleteBot()
    bot.run()
Пример #33
0
def main():
    bot = None
    action = None

    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()
    gen = None

    for arg in wikipedia.handleArgs():
        if action == None:
            action = arg
        else:
            generator = genFactory.handleArg(arg)
            if generator:
                gen = generator

    if action == 'export':
        if gen == None:
            wikipedia.output(
                u'\03{lightred}Export bot needs a page generator to itterate over.\03{default}'
            )
            return
        bot = GEExport(gen)
    elif action == 'import':
        bot = GEImport()
    if bot == None:
        wikipedia.output(
            u'\03{lightred}Invalid bot action to run.\03{default}')
        return
    bot.run()
Пример #34
0
def main():
    doCount = False
    argsList = []
    namespaces = []
    for arg in wikipedia.handleArgs():
        if arg == '-count':
            doCount = True
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[len('-namespace:'):]))
            except ValueError:
                namespaces.append(arg[len('-namespace:'):])
        else:
            argsList.append(arg)

    if doCount:
        robot = ReferencesRobot()
        if not argsList:
           argsList = templates
        choice = ''
        if 'reflist' in argsList:
            wikipedia.output(u'NOTE: it will take a long time to count "reflist".')
            choice = wikipedia.inputChoice(u'Proceed anyway?', ['yes', 'no', 'skip'], ['y', 'n', 's'], 'y')
            if choice == 's':
                argsList.remove('reflist')
        if choice <> 'n':
            robot.countRefs(argsList, namespaces)
    else:
        wikipedia.showHelp('refcheck')
def main(args):
    """
    Main loop. Get a generator and options.
    """
    generator = None
    parent = u""
    basename = u""
    always = False

    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == "-always":
            always = True
        elif arg.startswith("-parent:"):
            parent = arg[len("-parent:") :].strip()
        elif arg.startswith("-basename"):
            basename = arg[len("-basename:") :].strip()
        else:
            genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()
    if generator:
        for page in generator:
            createCategory(page, parent, basename)
    else:
        pywikibot.output(u"No pages to work on")

    pywikibot.output(u"All done")
Пример #36
0
def Manual_main():
    wikipedia.config.put_throttle = 0
    wikipedia.put_throttle.setDelay()
    gen= None
    word=u''
    PageTitles = []
    genFactory = pagegenerators.GeneratorFactory()
    for arg in wikipedia.handleArgs():
        if arg.startswith( '-page' ):
            PageTitles.append( arg[6:] )
            break
        else:
            generator = genFactory.handleArg( arg )
            if generator:
                gen = generator
    if PageTitles:
        pages = [wikipedia.Page(wikipedia.getSite(),PageTitle) for PageTitle in PageTitles]
        gen = iter( pages )
    if not gen:
        wikipedia.stopme()    
        sys.exit()
    preloadingGen = pagegenerators.PreloadingGenerator(gen,pageNumber = 60)
    for faTitle in preloadingGen:
        wikipedia.output(u'---'+faTitle.title()+u'-----')
        OurResult=main(faTitle.title(),word)
        OurResult=Open_json(OurResult,faTitle.title())
        if OurResult.strip():
            wikipedia.output(OurResult)
            with codecs.open(BotAdress_main+u'zz_most_miss_result.txt' ,mode = 'a',encoding = 'utf8' ) as f:
                f.write(OurResult.strip()+u'\n')
            with codecs.open(BotAdress_main+u'zz_most_miss_result_number.txt' ,mode = 'a',encoding = 'utf8' ) as f:
                f.write(OurResult.split(u'@')[0].strip()+u'\n')
Пример #37
0
def main():
    # This temporary array is used to read the page title if one single
    # page that should be unlinked.
    pageTitle = []
    # Which namespaces should be processed?
    # default to [] which means all namespaces will be processed
    namespaces = []
    always = False

    for arg in pywikibot.handleArgs():
        if arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[11:]))
            except ValueError:
                namespaces.append(arg[11:])
        elif arg == '-always':
            always = True
        else:
            pageTitle.append(arg)

    if pageTitle:
        page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
        bot = UnlinkBot(page, namespaces, always)
        bot.run()
    else:
        pywikibot.showHelp('unlink')
Пример #38
0
def main():
    oldImage = None
    newImage = None
    summary = ''
    always = False
    loose = False
    # read command line parameters
    for arg in pywikibot.handleArgs():
        if arg == '-always':
            always = True
        elif arg == '-loose':
            loose = True
        elif arg.startswith('-summary'):
            if len(arg) == len('-summary'):
                summary = pywikibot.input(u'Choose an edit summary: ')
            else:
                summary = arg[len('-summary:'):]
        else:
            if oldImage:
                newImage = arg
            else:
                oldImage = arg
    if not oldImage:
        pywikibot.showHelp('image')
    else:
        mysite = pywikibot.getSite()
        ns = mysite.image_namespace()
        oldImagePage = pywikibot.ImagePage(mysite, ns + ':' + oldImage)
        gen = pagegenerators.FileLinksGenerator(oldImagePage)
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = ImageRobot(preloadingGen, oldImage, newImage, summary, always,
                         loose)
        bot.run()
Пример #39
0
def main():
    oldImage = None
    newImage = None
    summary = ''
    always = False
    loose = False
    # read command line parameters
    for arg in pywikibot.handleArgs():
        if arg == '-always':
            always = True
        elif arg == '-loose':
            loose = True
        elif arg.startswith('-summary'):
            if len(arg) == len('-summary'):
                summary = pywikibot.input(u'Choose an edit summary: ')
            else:
                summary = arg[len('-summary:'):]
        else:
            if oldImage:
                newImage = arg
            else:
                oldImage = arg
    if not oldImage:
        pywikibot.showHelp('image')
    else:
        mysite = pywikibot.getSite()
        ns = mysite.image_namespace()
        oldImagePage = pywikibot.ImagePage(mysite, ns + ':' + oldImage)
        gen = pagegenerators.FileLinksGenerator(oldImagePage)
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = ImageRobot(preloadingGen, oldImage, newImage, summary, always,
                         loose)
        bot.run()
def main():
    countrycode = u''

    # Connect database, we need that
    (conn, cursor) = connectDatabase()
    (conn2, cursor2) = connectDatabase2()

    generator = None
    genFactory = pagegenerators.GeneratorFactory()

    for arg in wikipedia.handleArgs():
        if arg.startswith('-countrycode:'):
            countrycode = arg [len('-countrycode:'):]

    lang = wikipedia.getSite().language()
    wikipedia.setSite(wikipedia.getSite(u'commons', u'commons'))
    
    if countrycode:
	if not mconfig.countries.get((countrycode, lang)):
	    wikipedia.output(u'I have no config for countrycode "%s" in language "%s"' % (countrycode, lang))
	    return False
	wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
	locateCountry(countrycode, lang, mconfig.countries.get((countrycode, lang)), conn, cursor, conn2, cursor2)
    else:
	for (countrycode, lang), countryconfig in mconfig.countries.iteritems():
            if not countryconfig.get('autoGeocode'):
                wikipedia.output(u'"%s" in language "%s" is not supported in auto geocode mode (yet).' % (countrycode, lang))
            else:
                wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
                locateCountry(countrycode, lang, countryconfig, conn, cursor, conn2, cursor2)
Пример #41
0
def main():
    # read command line parameters
    for arg in pywikibot.handleArgs():
        pass  # No args yet

    bot = SpeedyRobot()
    bot.run()
Пример #42
0
def main():
    featured = False
    gen = None

    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == '-featured':
            featured = True
        else:
            genFactory.handleArg(arg)

    mysite = pywikibot.getSite()
    if mysite.sitename() == 'wikipedia:nl':
        pywikibot.output(
            u'\03{lightred}There is consensus on the Dutch Wikipedia that bots should not be used to fix redirects.\03{default}')
        sys.exit()

    if featured:
        featuredList = pywikibot.translate(mysite, featured_articles)
        ref = pywikibot.Page(pywikibot.getSite(), featuredList)
        gen = pagegenerators.ReferringPageGenerator(ref)
        gen = pagegenerators.NamespaceFilterPageGenerator(gen, [0])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if gen:
        for page in pagegenerators.PreloadingGenerator(gen):
            workon(page)
    else:
        pywikibot.showHelp('fixing_redirects')
Пример #43
0
def main():
    global always
    always = False

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

    mysite = pywikibot.getSite()
    # If anything needs to be prepared, you can do it here
    template_image = pywikibot.translate(pywikibot.getSite(),
                                         template_to_the_image)
    template_user = pywikibot.translate(pywikibot.getSite(),
                                        template_to_the_user)
    except_text_translated = pywikibot.translate(pywikibot.getSite(),
                                                 except_text)
    basicgenerator = pagegenerators.UnusedFilesGenerator()
    generator = pagegenerators.PreloadingGenerator(basicgenerator)
    for page in generator:
        pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                         % page.title())
        if except_text_translated not in page.getImagePageHtml() and \
           'http://' not in page.get():
            pywikibot.output(u'\n' + page.title())
            if template_image in page.get():
                pywikibot.output(u"%s done already" % page.aslink())
                continue
            appendtext(page, u"\n\n"+template_image)
            uploader = page.getFileVersionHistory().pop()[1]
            usertalkname = u'User Talk:%s' % uploader
            usertalkpage = pywikibot.Page(mysite, usertalkname)
            msg2uploader = template_user % {'title': page.title()}
            appendtext(usertalkpage, msg2uploader)
Пример #44
0
def main(args):
    '''
    Main loop.
    '''
    start_page = 0
    end_page = 5
    per = 100
    for arg in wikipedia.handleArgs():
        if arg.startswith('-start_page'):
            if len(arg) == 11:
                start_page = wikipedia.input(u'What is the id of the photo you want to start at?')
            else:
                start_page = arg[12:]
        elif arg.startswith('-end_page'):
            if len(arg) == 9:
                end_page = wikipedia.input(u'What is the id of the photo you want to end at?')
            else:
                end_page = arg[10:]
	elif arg.startswith('-per'):
	    if len(arg) == 4:
		per = wikipedia.input(u'How much images per page?')
	    else:
		per = arg[5:]

    processGalleries(int(start_page), int(end_page), int(per))
def main():
    countrycode = u''
    conn = None
    cursor = None
    # Connect database, we need that
    (conn, cursor) = connectDatabase()
    (conn2, cursor2) = connectDatabase2()
    
    for arg in wikipedia.handleArgs():
        if arg.startswith('-countrycode:'):
            countrycode = arg [len('-countrycode:'):]

    if countrycode:
        lang = wikipedia.getSite().language()
	if not mconfig.countries.get((countrycode, lang)):
	    wikipedia.output(u'I have no config for countrycode "%s" in language "%s"' % (countrycode, lang))
	    return False
	wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
	processCountry(countrycode, lang, mconfig.countries.get((countrycode, lang)), conn, cursor, conn2, cursor2)
    else:
        totals = {}
	for (countrycode, lang), countryconfig in mconfig.countries.iteritems():
	    wikipedia.output(u'Working on countrycode "%s" in language "%s"' % (countrycode, lang))
	    totals[(countrycode, lang)] = processCountry(countrycode, lang, countryconfig, conn, cursor, conn2, cursor2)
	makeStatistics(mconfig, totals)
Пример #46
0
def main(args):
    '''
    Main loop. Get a generator and options. Work on all images in the generator.
    '''
    generator = None
    onlyFilter = False
    onlyUncat = False
    genFactory = pagegenerators.GeneratorFactory()

    global search_wikis
    global hint_wiki

    site = pywikibot.getSite(u'commons', u'commons')
    pywikibot.setSite(site)
    for arg in pywikibot.handleArgs():
        if arg == '-onlyfilter':
            onlyFilter = True
        elif arg == '-onlyuncat':
            onlyUncat = True
        elif arg.startswith('-hint:'):
            hint_wiki = arg [len('-hint:'):]
        elif arg.startswith('-onlyhint'):
            search_wikis = arg [len('-onlyhint:'):]
        else:
            genFactory.handleArg(arg)

    generator = genFactory.getCombinedGenerator()
    if not generator:
        generator = pagegenerators.CategorizedPageGenerator(
            catlib.Category(site, u'Category:Media needing categories'),
            recurse=True)
    initLists()
    categorizeImages(generator, onlyFilter, onlyUncat)
    pywikibot.output(u'All done')
def main():
    # The generator gives the pages that should be worked upon.
    gen = None
    # If debug is True, doesn't do any real changes, but only show
    # what would have been changed.
    debug = False
    wantHelp = False

    cat = catlib.Category(wikipedia.getSite(), 'Category:%s' % 'Instance')
    gen = pagegenerators.CategorizedPageGenerator(cat, start = None, recurse = False)

    # Parse command line arguments
    for arg in wikipedia.handleArgs():
        if arg.startswith("-debug"):
            debug = True
        else:
            print arg, "yielding wanthelp"
            wantHelp = True

    if not wantHelp:
        # The preloading generator is responsible for downloading multiple
        # pages from the wiki simultaneously.
        gen = pagegenerators.PreloadingGenerator(gen)
        bot = PuppetUnmanagedListBot(gen, debug)
        bot.run()
    else:
        wikipedia.showHelp()
Пример #48
0
def main():
    import os
    index = None
    djvu = None
    pages = None
    # what would have been changed.
    dry = False
    ask = False
    overwrite = 'ask'

    # Parse command line arguments
    for arg in pywikibot.handleArgs():
        if arg.startswith("-dry"):
            dry = True
        elif arg.startswith("-ask"):
            ask = True
        elif arg.startswith("-overwrite:"):
            overwrite = arg[11:12]
            if overwrite != 'y' and overwrite != 'n':
                pywikibot.output(u"Unknown argument %s; will ask before overwriting" % arg)
                overwrite = 'ask'
        elif arg.startswith("-djvu:"):
            djvu = arg[6:]
        elif arg.startswith("-index:"):
            index = arg[7:]
        elif arg.startswith("-pages:"):
            pages = arg[7:]
        else:
            pywikibot.output(u"Unknown argument %s" % arg)

    # Check the djvu file exists
    if djvu:
        os.stat(djvu)

        if not index:
            import os.path
            index = os.path.basename(djvu)

    if djvu and index:
        site = pywikibot.getSite()
        index_page = pywikibot.Page(site, index)

        if site.family.name != 'wikisource':
            raise pywikibot.PageNotFound(u"Found family '%s'; Wikisource required." % site.family.name)

        if not index_page.exists() and index_page.namespace() == 0:
            index_namespace = site.mediawiki_message('Proofreadpage index namespace')

            index_page = pywikibot.Page(pywikibot.getSite(),
                                        u"%s:%s" % (index_namespace, index))
        if not index_page.exists():
            raise pywikibot.NoPage(u"Page '%s' does not exist" % index)
        pywikibot.output(u"uploading text from %s to %s"
                         % (djvu, index_page.title(asLink=True)) )
        bot = DjVuTextBot(djvu, index, pages, ask, overwrite, dry)
        if not bot.has_text():
            raise ValueError("No text layer in djvu file")
        bot.run()
    else:
        pywikibot.showHelp()
Пример #49
0
def main():
    # Adapt these to the file you are using. 'pageStartMarker' and 'pageEndMarker' are
    # the beginning and end of each entry. Take text that should be included
    # and does not occur elsewhere in the text.

    # TODO: make config variables for these.
    filename = "dict.txt"
    pageStartMarker = "{{-start-}}"
    pageEndMarker = "{{-stop-}}"
    titleStartMarker = u"'''"
    titleEndMarker = u"'''"

    include = False
    force = False
    append = None
    notitle = False
    summary = None
    minor = False
    autosummary = False
    dry = False

    for arg in wikipedia.handleArgs():
        if arg.startswith("-start:"):
            pageStartMarker = arg[7:]
        elif arg.startswith("-end:"):
            pageEndMarker = arg[5:]
        elif arg.startswith("-file:"):
            filename = arg[6:]
        elif arg == "-include":
            include = True
        elif arg == "-appendtop":
            append = "Top"
        elif arg == "-appendbottom":
            append = "Bottom"
        elif arg == "-force":
            force=True
        elif arg == "-dry":
            dry = True
        elif arg == "-safe":
            force = False
            append = None
        elif arg == '-notitle':
            notitle = True
        elif arg == '-minor':
            minor = True
        elif arg.startswith("-titlestart:"):
            titleStartMarker = arg[12:]
        elif arg.startswith("-titleend:"):
            titleEndMarker = arg[10:]
        elif arg.startswith("-summary:"):
            summary = arg[9:]
        elif arg == '-autosummary':
            autosummary = True
        else:
            wikipedia.output(u"Disregarding unknown argument %s." % arg)

    reader = PageFromFileReader(filename, pageStartMarker, pageEndMarker, titleStartMarker, titleEndMarker, include, notitle)

    bot = PageFromFileRobot(reader, force, append, summary, minor, autosummary, dry)
    bot.run()
Пример #50
0
def main():
    global mysite, linktrail, page
    start = []
    for arg in wikipedia.handleArgs():
        start.append(arg)
    if start:
        start = " ".join(start)
    else:
        start = "!"
    mysite = wikipedia.getSite()
    linktrail = mysite.linktrail()
    try:
        generator = pagegenerators.CategorizedPageGenerator(mysite.disambcategory(), start = start)
    except wikipedia.NoPage:
        print "The bot does not know the disambiguation category for your wiki."
        raise
    # only work on articles
    generator = pagegenerators.NamespaceFilterPageGenerator(generator, [0])
    generator = pagegenerators.PreloadingGenerator(generator)
    pagestodo = []
    pagestoload = []
    for page in generator:
        if page.isRedirectPage():
            continue
        linked = page.linkedPages()
        pagestodo.append((page,linked))
        pagestoload += linked
        if len(pagestoload) > 49:
            wikipedia.getall(mysite,pagestoload)
            for page, links in pagestodo:
                workon(page,links)
            pagestoload = []
            pagestodo = []
Пример #51
0
def main():  
    # If debug is True, don't edit pages, but only show what would have been
    # changed.
    debug = False
    # The AfD log that should be treated.
    date = None
    # Whether to confirm edits.
    always = False

    # Parse command line arguments
    for arg in wikipedia.handleArgs():
        if arg.startswith('-debug'):
            wikipedia.output(u'Debug mode.')
            debug = True
        elif arg.startswith('-date'):        
            if len(arg) == 5:
                date = wikipedia.input(u'Please enter the date of the log that should be treated (yyyymmdd):')
            else:
                date = arg[6:]
        elif arg.startswith('-always'):
            always = True
  
    if date:
        page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % date
    else:
        page_title = u'Wikipedia:Te verwijderen pagina\'s/Toegevoegd %s' % time.strftime("%Y%m%d", time.localtime(time.time()-60*60*24))

    wikipedia.output(u'Checking: %s.' % page_title)
    page = wikipedia.Page(wikipedia.getSite(code = 'nl', fam = 'wikipedia'), page_title)
    bot = AfDBot(page, always, debug)
    bot.run()
Пример #52
0
def main():
    genFactory = pagegenerators.GeneratorFactory()
    commandline_arguments = list()
    templateTitle = u''
    for arg in pywikibot.handleArgs():
        if arg.startswith('-template'):
            if len(arg) == 9:
                templateTitle = pywikibot.input(
                    u'Please enter the template to work on:')
            else:
                templateTitle = arg[10:]
        elif genFactory.handleArg(arg):
            continue
        else:
            commandline_arguments.append(arg)
    
    if len(commandline_arguments) % 2 or not templateTitle:
        raise ValueError  # or something.
    fields = dict()

    for i in xrange (0, len(commandline_arguments), 2):
        fields[commandline_arguments[i]] = commandline_arguments[i+1]
    if templateTitle:
        gen = pagegenerators.ReferringPageGenerator(pywikibot.Page(pywikibot.getSite(),"Template:%s" % templateTitle ), onlyTemplateInclusion = True)
    else:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        # TODO: Build a transcluding generator based on templateTitle
        return
    
    bot = HarvestRobot(gen, templateTitle, fields)
    bot.run()
Пример #53
0
def main(*args):
    url = u''
    description = []
    keepFilename = False
    useFilename = None
    verifyDescription = True

    # process all global bot args
    # returns a list of non-global args, i.e. args for upload.py
    for arg in pywikibot.handleArgs(*args):
        if arg:
            if arg.startswith('-keep'):
                keepFilename = True
            elif arg.startswith('-filename:'):
                useFilename = arg[10:]
            elif arg.startswith('-noverify'):
                verifyDescription = False
            elif url == u'':
                url = arg
            else:
                description.append(arg)
    description = u' '.join(description)
    bot = UploadRobot(url, description=description, useFilename=useFilename,
                      keepFilename=keepFilename,
                      verifyDescription=verifyDescription)
    bot.run()
Пример #54
0
def main():
    doCount = False
    argsList = []
    namespaces = []
    for arg in wikipedia.handleArgs():
        if arg == '-count':
            doCount = True
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[len('-namespace:'):]))
            except ValueError:
                namespaces.append(arg[len('-namespace:'):])
        else:
            argsList.append(arg)

    if doCount:
        robot = ReferencesRobot()
        if not argsList:
           argsList = templates
        choice = ''
        if 'reflist' in argsList:
            wikipedia.output(u'NOTE: it will take a long time to count "reflist".')
            choice = wikipedia.inputChoice(u'Proceed anyway?', ['yes', 'no', 'skip'], ['y', 'n', 's'], 'y')
            if choice == 's':
                argsList.remove('reflist')
        if choice <> 'n':
            robot.countRefs(argsList, namespaces)
    else:
        wikipedia.showHelp('refcheck')
Пример #55
0
def main():
    #page generator
    gen = None
    # If the user chooses to work on a single page, this temporary array is
    # used to read the words from the page title. The words will later be
    # joined with spaces to retrieve the full title.
    pageTitle = []
    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if not genFactory.handleArg(arg):
            pageTitle.append(arg)

    if pageTitle:
        # work on a single page
        page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
        gen = iter([page])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        pywikibot.showHelp('inline_images')
    else:
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = InlineImagesRobot(preloadingGen)
        bot.run()
Пример #56
0
def main(*args):
    # Disable cosmetic changes because we don't want to modify any page
    # content, so that we don't flood the histories with minor changes.
    config.cosmetic_changes = False
    #page generator
    gen = None
    genFactory = pagegenerators.GeneratorFactory()
    redirs = False
    # If the user chooses to work on a single page, this temporary array is
    # used to read the words from the page title. The words will later be
    # joined with spaces to retrieve the full title.
    pageTitle = []
    for arg in pywikibot.handleArgs(*args):
        if genFactory.handleArg(arg):
            continue
        if arg == '-redir':
            redirs = True
        else:
            pageTitle.append(arg)

    gen = genFactory.getCombinedGenerator()
    if not gen:
        if pageTitle:
            # work on a single page
            page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
            gen = iter([page])
        else:
            pywikibot.showHelp()
            return
    preloadingGen = pagegenerators.PreloadingGenerator(gen)
    bot = TouchBot(preloadingGen, redirs)
    bot.run()
Пример #57
0
def main():
    # This temporary array is used to read the page title if one single
    # page that should be unlinked.
    pageTitle = []
    # Which namespaces should be processed?
    # default to [] which means all namespaces will be processed
    namespaces = []
    always = False

    for arg in pywikibot.handleArgs():
        if arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[11:]))
            except ValueError:
                namespaces.append(arg[11:])
        elif arg == '-always':
            always = True
        else:
            pageTitle.append(arg)

    if pageTitle:
        page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
        bot = UnlinkBot(page, namespaces, always)
        bot.run()
    else:
        pywikibot.showHelp('unlink')
Пример #58
0
def main(args):
    pywikibot.output(u'WARNING: This is an experimental bot')
    pywikibot.output(
        u'WARNING: It will only work on self published work images')
    pywikibot.output(u'WARNING: This bot is still full of bugs')
    pywikibot.output(u'WARNING: Use at your own risk!')

    generator = None
    autonomous = False
    checkTemplate = True

    # Load a lot of default generators
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if arg == '-nochecktemplate':
            checkTemplate = False
        elif arg == '-autonomous':
            autonomous = True
        else:
            genFactory.handleArg(arg)

    if not supportedSite():
        pywikibot.output(u'Sorry, this site is not supported (yet).')
        return False

    generator = genFactory.getCombinedGenerator()
    if not generator:
        raise add_text.NoEnoughData(
            'You have to specify the generator you want to use for the script!'
        )

    pregenerator = pagegenerators.PreloadingGenerator(generator)

    prefetchQueue = Queue(maxsize=50)
    uploadQueue = Queue(maxsize=200)

    imageFetcherThread = imageFetcher(pregenerator, prefetchQueue)
    userInteractionThread = userInteraction(prefetchQueue, uploadQueue)
    uploaderThread = uploader(uploadQueue)

    imageFetcherThread.daemon = False
    userInteractionThread.daemon = False
    uploaderThread.daemon = False

    if autonomous:
        pywikibot.output(
            u'Bot is running in autonomous mode. There will be no user interaction.'
        )
        userInteractionThread.setAutonomous()

    if not checkTemplate:
        pywikibot.output(
            u'No check template will be added to the uploaded files.')
        uploaderThread.nochecktemplate()

    fetchDone = imageFetcherThread.start()
    userDone = userInteractionThread.start()
    uploadDone = uploaderThread.start()
Пример #59
0
def main():
    #page generator
    gen = None
    # This temporary array is used to read the page title if one single
    # page to work on is specified by the arguments.
    pageTitle = []
    # Which namespaces should be processed?
    # default to [] which means all namespaces will be processed
    namespaces = []
    # This factory is responsible for processing command line arguments
    # that are also used by other scripts and that determine on which pages
    # to work on.
    genFactory = pagegenerators.GeneratorFactory()
    always = False

    for arg in pywikibot.handleArgs():
        if arg.startswith('-xml'):
            if len(arg) == 4:
                xmlFilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename:')
            else:
                xmlFilename = arg[5:]
            gen = XmlDumpSelflinkPageGenerator(xmlFilename)
        elif arg == '-sql':
            # NOT WORKING YET
            query = """
SELECT page_namespace, page_title
FROM page JOIN pagelinks JOIN text ON (page_id = pl_from AND page_id = old_id)
WHERE pl_title = page_title
AND pl_namespace = page_namespace
AND page_namespace = 0
AND (old_text LIKE concat('%[[', page_title, ']]%')
    OR old_text LIKE concat('%[[', page_title, '|%'))
LIMIT 100"""
            gen = pagegenerators.MySQLPageGenerator(query)
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[11:]))
            except ValueError:
                namespaces.append(arg[11:])
        elif arg == '-always':
            always = True
        else:
            if not genFactory.handleArg(arg):
                pageTitle.append(arg)

    if pageTitle:
        page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle))
        gen = iter([page])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        pywikibot.showHelp('selflink')
    else:
        if namespaces != []:
            gen =  pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = SelflinkBot(preloadingGen, always)
        bot.run()
Пример #60
0
def main(args):
    '''
    Main loop.
    '''

    genFactory = pagegenerators.GeneratorFactory()

    start_id = 0
    end_id = 0
    updaterun = False
    site = wikipedia.getSite('commons', 'commons')
    wikipedia.setSite(site)
    updatePage = wikipedia.Page(site, u'User:BotMultichillT/Air_Force_latest')
    interval = 100

    for arg in wikipedia.handleArgs():
        if arg.startswith('-start_id'):
            if len(arg) == 9:
                start_id = wikipedia.input(
                    u'What is the id of the photo you want to start at?')
            else:
                start_id = arg[10:]
        elif arg.startswith('-end_id'):
            if len(arg) == 7:
                end_id = wikipedia.input(
                    u'What is the id of the photo you want to end at?')
            else:
                end_id = arg[8:]
        elif arg == u'-updaterun':
            updaterun = True
        elif arg.startswith('-interval'):
            if len(arg) == 9:
                interval = wikipedia.input(
                    u'What interval do you want to use?')
            else:
                interval = arg[10:]
        else:
            genFactory.handleArg(arg)
    generator = genFactory.getCombinedGenerator()
    # Do we have a pagenerator?
    if generator:
        for page in generator:
            if page.namespace() == 14:
                processCategory(page)

    # Is updaterun set?
    elif updaterun:
        start_id = int(updatePage.get())
        end_id = start_id + int(interval)
        last_id = processPhotos(int(start_id), int(end_id))
        comment = u'Worked from ' + str(start_id) + u' to ' + str(last_id)
        updatePage.put(str(last_id), comment)

    # Do we have a start_id and a end_id
    elif int(start_id) > 0 and int(end_id) > 0:
        last_id = processPhotos(int(start_id), int(end_id))
    # Use the default generator
    else:
        print "Screw this, will implement later"