How to use the pywikibot.input function in pywikibot

To help you get started, we’ve selected a few pywikibot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wikimedia / pywikibot / scripts / checkimages.py View on Github external
for ns in site.namespace(Namespace.FILE, all))
            if firstPageTitle.startswith(namespaces):
                firstPageTitle = firstPageTitle.split(':')[1]
            generator = site.allimages(start=firstPageTitle)
            repeat = False
        elif arg.startswith('-page'):
            if len(arg) == 5:
                regexPageName = str(pywikibot.input(
                    'Which page do you want to use for the regex?'))
            elif len(arg) > 5:
                regexPageName = str(arg[6:])
            repeat = False
            regexGen = True
        elif arg.startswith('-url'):
            if len(arg) == 4:
                regexPageUrl = str(pywikibot.input(
                    'Which url do you want to use for the regex?'))
            elif len(arg) > 4:
                regexPageUrl = str(arg[5:])
            urlUsed = True
            repeat = False
            regexGen = True
        elif arg.startswith('-regex'):
            if len(arg) == 6:
                regexpToUse = str(pywikibot.input(
                    'Which regex do you want to use?'))
            elif len(arg) > 6:
                regexpToUse = str(arg[7:])
            generator = 'regex'
            repeat = False
        elif arg.startswith('-cat'):
            if len(arg) == 4:
github wikimedia / pywikibot / scripts / casechecker.py View on Github external
def __init__(self):
        """Initializer with arg parsing."""
        for arg in pywikibot.handle_args():
            arg, sep, value = arg.partition(':')
            if arg == '-from':
                self.apfrom = value or pywikibot.input(
                    'Which page to start from: ')
            elif arg == '-reqsize':
                self.aplimit = int(value)
            elif arg == '-links':
                self.links = True
            elif arg == '-linksonly':
                self.links = True
                self.titles = False
            elif arg == '-replace':
                self.replace = True
            elif arg == '-redir':
                self.filterredir = 'all'
            elif arg == '-redironly':
                self.filterredir = 'redirects'
            elif arg == '-limit':
                self.stopAfter = int(value)
github wikimedia / pywikibot / scripts / checkimages.py View on Github external
elif len(arg) > 5:
                regexPageName = str(arg[6:])
            repeat = False
            regexGen = True
        elif arg.startswith('-url'):
            if len(arg) == 4:
                regexPageUrl = str(pywikibot.input(
                    'Which url do you want to use for the regex?'))
            elif len(arg) > 4:
                regexPageUrl = str(arg[5:])
            urlUsed = True
            repeat = False
            regexGen = True
        elif arg.startswith('-regex'):
            if len(arg) == 6:
                regexpToUse = str(pywikibot.input(
                    'Which regex do you want to use?'))
            elif len(arg) > 6:
                regexpToUse = str(arg[7:])
            generator = 'regex'
            repeat = False
        elif arg.startswith('-cat'):
            if len(arg) == 4:
                catName = str(pywikibot.input('In which category do I work?'))
            elif len(arg) > 4:
                catName = str(arg[5:])
            catSelected = pywikibot.Category(site,
                                             'Category:{}'.format(catName))
            generator = catSelected.articles(namespaces=[6])
            repeat = False
        elif arg.startswith('-ref'):
            if len(arg) == 4:
github wikimedia / pywikibot / scripts / editarticle.py View on Github external
def setpage(self):
        """Set page and page title."""
        page_title = self.options.page or pywikibot.input('Page to edit:')
        self.page = pywikibot.Page(pywikibot.Link(page_title, self.site))
        if not self.options.edit_redirect and self.page.isRedirectPage():
            self.page = self.page.getRedirectTarget()
github wikimedia / pywikibot / scripts / add_text.py View on Github external
local_args = pywikibot.handle_args(args)
    genFactory = pagegenerators.GeneratorFactory()

    # Loading the arguments
    for arg in local_args:
        option, sep, value = arg.partition(':')
        if option == '-textfile':
            textfile = value or pywikibot.input(
                'Which textfile do you want to add?')
        elif option == '-text':
            addText = value or pywikibot.input('What text do you want to add?')
        elif option == '-summary':
            summary = value or pywikibot.input(
                'What summary do you want to use?')
        elif option == '-excepturl':
            regexSkipUrl = value or pywikibot.input('What text should I skip?')
        elif option == '-except':
            regexSkip = value or pywikibot.input('What text should I skip?')
        elif option == '-up':
            up = True
        elif option == '-noreorder':
            reorderEnabled = False
        elif option == '-always':
            always = True
        elif option in ('-talk', '-talkpage'):
            talkPage = True
        else:
            genFactory.handleArg(arg)

    if textfile and not addText:
        with codecs.open(textfile, 'r', config.textfile_encoding) as f:
            addText = f.read()
github wikimedia / pywikibot / scripts / imageharvest.py View on Github external
else:
        basicdesc = desc

    if image_url:
        ilinks = []
        i = minimum
        while i <= maximum:
            ilinks += [url.replace('$', str(i))]
            i += 1
    else:
        ilinks = get_imagelinks(url)

    for image in ilinks:
        if pywikibot.input_yn('Include image {}?'.format(image), default=False,
                              automatic_quit=False):
            desc = pywikibot.input('Give the description of this image:')
            categories = []
            while True:
                cat = pywikibot.input('Specify a category (or press enter to '
                                      'end adding categories)')
                if not cat.strip():
                    break
                if ':' in cat:
                    categories.append('[[{}]]'.format(cat))
                else:
                    categories.append('[[{}:{}]]'
                                      .format(mysite.namespace(14), cat))
            desc += '\n\n' + basicdesc + '\n\n' + '\n'.join(categories)
            UploadRobot(image, description=desc).run()
        elif answer == 's':
            break
github wikimedia / pywikibot / scripts / image.py View on Github external
    @param args: command line arguments
    @type args: unicode
    """
    old_image = None
    new_image = None
    options = {}

    for arg in pywikibot.handle_args(args):
        if arg == '-always':
            options['always'] = True
        elif arg == '-loose':
            options['loose'] = True
        elif arg.startswith('-summary'):
            if len(arg) == len('-summary'):
                options['summary'] = pywikibot.input(
                    'Choose an edit summary: ')
            else:
                options['summary'] = arg[len('-summary:'):]
        elif old_image:
            new_image = arg
        else:
            old_image = arg

    if old_image:
        site = pywikibot.Site()
        old_imagepage = pywikibot.FilePage(site, old_image)
        gen = pagegenerators.FileLinksGenerator(old_imagepage)
        preloading_gen = pagegenerators.PreloadingGenerator(gen)
        bot = ImageRobot(preloading_gen, old_image, new_image,
                         site=site, **options)
        bot.run()
github pywikibot-catfiles / file-metadata / file_metadata / wikibot / generate_user_files.py View on Github external
elif len(known_langs) == 1:
        pywikibot.output('The only known language: {0}'.format(known_langs[0]))
        default_lang = known_langs[0]
    else:
        pywikibot.output("This is the list of known languages:")
        pywikibot.output(u", ".join(known_langs))
        if default_lang not in known_langs:
            if default_lang != 'en' and 'en' in known_langs:
                default_lang = 'en'
            else:
                default_lang = None
    message = "The language code of the site we're working on"

    mylang = None
    while not mylang:
        mylang = pywikibot.input(message, default=default_lang, force=force)
        if known_langs and mylang and mylang not in known_langs:
            if not pywikibot.input_yn("The language code {0} is not in the "
                                      "list of known languages. Do you want "
                                      "to continue?".format(mylang),
                                      default=False, automatic_quit=False):
                mylang = None

    message = u"Username on {0}:{1}".format(mylang, fam.name)
    username = pywikibot.input(message, default=default_username, force=force)
    # Escape ''s
    if username:
        username = username.replace("'", "\\'")
    return fam.name, mylang, username
github wikimedia / pywikibot / scripts / category.py View on Github external
move_together=move_together,
                                keep_sortkey=keep_sortkey)
    elif action == 'tidy':
        cat_title = pywikibot.input('Which category do you want to tidy up?')
        bot = CategoryTidyRobot(cat_title, cat_db, gen_factory.namespaces,
                                summary)
    elif action == 'tree':
        catTitle = pywikibot.input(
            'For which category do you want to create a tree view?')
        filename = pywikibot.input(
            'Please enter the name of the file where the tree should be saved,'
            '\nor press enter to simply show the tree:')
        bot = CategoryTreeRobot(catTitle, cat_db, filename, depth)
    elif action == 'listify':
        if not from_given:
            old_cat_title = pywikibot.input(
                'Please enter the name of the category to listify:')
        if not to_given:
            new_cat_title = pywikibot.input(
                'Please enter the name of the list to create:')
        bot = CategoryListifyRobot(old_cat_title, new_cat_title, summary,
                                   append, overwrite, showimages, subCats=True,
                                   talkPages=talkpages, recurse=recurse)

    if bot:
        pywikibot.Site().login()
        suggest_help(unknown_parameters=unknown)
        try:
            bot.run()
        except pywikibot.Error:
            pywikibot.error('Fatal error:', exc_info=True)
        finally:
github wikimedia / pywikibot / scripts / illustrate_wikidata.py View on Github external
If args is an empty list, sys.argv is used.

    @param args: command line arguments
    @type args: unicode
    """
    # Process global args and prepare generator args parser
    local_args = pywikibot.handle_args(args)
    generator_factory = pagegenerators.GeneratorFactory()

    wdproperty = 'P18'

    for arg in local_args:
        if arg.startswith('-property'):
            if len(arg) == 9:
                wdproperty = pywikibot.input(
                    'Please enter the property you want to add:')
            else:
                wdproperty = arg[10:]
        else:
            generator_factory.handleArg(arg)

    generator = generator_factory.getCombinedGenerator(preload=True)
    if not generator:
        pywikibot.bot.suggest_help(missing_generator=True)
        return False

    bot = IllustrateRobot(generator, wdproperty)
    bot.run()
    return True