コード例 #1
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)
コード例 #2
0
    def getReasonForDeletion(self, page):
        suggestedReason = self.guessReasonForDeletion(page)
        pywikibot.output(u"The suggested reason is: \03{lightred}%s\03{default}" % suggestedReason)

        # We don't use pywikibot.translate() here because for some languages the
        # entry is intentionally left out.
        if self.mySite.family.name in self.delete_reasons:
            if page.site().lang in self.delete_reasons[self.mySite.family.name]:
                localReasons = pywikibot.translate(page.site().lang, self.delete_reasons)
                pywikibot.output(u"")
                localReasoneKey = localReasons.keys()
                localReasoneKey.sort()
                for key in localReasoneKey:
                    pywikibot.output((key + ":").ljust(8) + localReasons[key])
                pywikibot.output(u"")
                reason = pywikibot.input(
                    u"Please enter the reason for deletion, choose a default reason, or press enter for the suggested message:"
                )
                if reason.strip() in localReasons:
                    reason = localReasons[reason]
            else:
                reason = pywikibot.input(
                    u"Please enter the reason for deletion, or press enter for the suggested message:"
                )
        else:
            reason = pywikibot.input(u"Please enter the reason for deletion, or press enter for the suggested message:")

        if not reason:
            reason = suggestedReason
        return reason
コード例 #3
0
ファイル: osm2wiki_coord.py プロジェクト: edgarskos/wikiro
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)
コード例 #4
0
ファイル: fema_bot.py プロジェクト: bymerej/ts-multichill-bot
def main(args):
    '''
    Main loop.
    '''
    start_id = 0
    end_id   = 45000
    latest = False
    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'-latest':
            latest = True
    
    if latest:
	processLatestPhotos()
    else:
	processPhotos(int(start_id), int(end_id))
コード例 #5
0
ファイル: army_bot.py プロジェクト: bymerej/ts-multichill-bot
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))
コード例 #6
0
ファイル: osm2wiki_template.py プロジェクト: edgarskos/wikiro
def main():
	lang=pywikibot.getSite().language()
	start = None
	# Loading the arguments
	for arg in pywikibot.handleArgs():
		if arg.startswith('-lang'):
			if len(arg) == 5:
				lang = pywikibot.input(u'What language do you want to use?')
			else:
				lang = arg[6:]
		elif arg.startswith('-start'):
			if len(arg) == 6:
				start = pywikibot.input(u'What article do you want to start with?')
			else:
				start = arg[7:]
	
	bot = o2wVillageData()
	# bot.tl2Dict(bot.extractTemplate(u"""{{Infocaseta Așezare
# | nume = Bogdănești
# | alt_nume = 
# | tip_asezare = Sat
# | imagine = 
# | imagine_dimensiune = 250px
# | imagine_descriere = Bogdănești
# | stemă = 
# | hartă = 
# | pushpin_map = 
# | pushpin_label_position = right
# | tip_subdiviziune = Țară
# | nume_subdiviziune = {{ROU}}
# | tip_subdiviziune1 = [[Județele României|Județ]]
# | nume_subdiviziune1 = [[județul Vaslui|Vaslui]]
# | tip_subdiviziune3 = [[Comunele României|Comună]]
# | nume_subdiviziune3 = [[Comuna Bogdănești, Vaslui|Bogdănești]]
# | titlu_atestare = Prima atestare
# | atestare = 
# | suprafață_totală_km2 = 
# | altitudine = 
# | latd = 46
# | latm = 26
# | lats = 58
# | latNS = N
# | longd = 27
# | longm = 43
# | longs = 36
# | longEV = E
# | recensământ = 2002
# | populație = 
# | populație_note_subsol = 
# | tip_cod_poștal = [[Cod poștal]]
# | codpoștal = 
# | camp_gol_nume =
# | camp_gol_info = 
# }}

# '''Bogdănești''' este o localitate în [[județul Vaslui]], [[Moldova]], [[România]]
# """, u"Infocaseta Așezare"))
	# print bot._dict
	bot.putCoordOnWiki(lang, start)
コード例 #7
0
def main():
    summary_commandline,template,gen = None,None,None
    exceptions,PageTitles,namespaces = [],[],[]
    cat=''
    autoText,autoTitle = False,False
    genFactory = pagegenerators.GeneratorFactory()
    arg=False#------if you dont want to work with arguments leave it False if you want change it to True---
    if arg==False:
        for arg in wikipedia.handleArgs():
            if arg == '-autotitle':
                autoTitle = True
            elif arg == '-autotext':
                autoText = True
            elif arg.startswith( '-page:' ):
                if len(arg) == 6:
                    PageTitles.append(wikipedia.input( u'Which page do you want to chage?' ))
                else:
                    PageTitles.append(arg[6:])
            elif arg.startswith( '-cat:' ):
                if len(arg) == 5:
                    cat=wikipedia.input( u'Which Category do you want to chage?' )
                else:
                    cat='Category:'+arg[5:]
            elif arg.startswith( '-template:' ):
                if len(arg) == 10:
                    template.append(wikipedia.input( u'Which Template do you want to chage?' ))
                else:
                    template.append('Template:'+arg[10:])
            elif arg.startswith('-except:'):
                exceptions.append(arg[8:])
            elif arg.startswith( '-namespace:' ):
                namespaces.append( int( arg[11:] ) )
            elif arg.startswith( '-ns:' ):
                namespaces.append( int( arg[4:] ) )    
            elif arg.startswith( '-summary:' ):
                wikipedia.setAction( arg[9:] )
                summary_commandline = True
            else:
                generator = genFactory.handleArg(arg)
                if generator:
                    gen = generator
    else:
        PageTitles = [raw_input(u'Page:> ').decode('utf-8')]
    if cat!='':
        facatfalist=facatlist(cat)
        if facatfalist!=False:
            run(facatfalist)    
    if PageTitles:
        pages = [wikipedia.Page(faSite,PageTitle) for PageTitle in PageTitles]
        gen = iter( pages )
    if not gen:
        wikipedia.stopme()
        sys.exit()
    if namespaces != []:
        gen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
    preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60 )#---number of pages that you want load at same time
    run(preloadingGen)
コード例 #8
0
 def askForCaptcha(self, url):
     try:
         import webbrowser
         wikipedia.output(u'Opening CAPTCHA in your web browser...')
         webbrowser.open(url)
         return wikipedia.input(u'What is the solution of the CAPTCHA that is shown in your web browser?')
     except:
         wikipedia.output(u'Error in opening web browser: %s' % sys.exc_info()[0])
         return wikipedia.input(u'What is the solution of the CAPTCHA at %s ?' % url)
コード例 #9
0
ファイル: air_force_bot.py プロジェクト: multichill/toollabs
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"
コード例 #10
0
def main(page=None):
    # if -file is not used, this temporary array is used to read the page title.
    pageTitle = []
    #    start = pywikibot.input('where to start?')
    #    basicgenerator = pagegenerators.AllpagesPageGenerator('!', 6)
    #    gen = pagegenerators.PreloadingGenerator(basicgenerator)
    gen = None
    interwiki = False
    keep_name = False
    targetLang = None
    targetFamily = None

    for arg in pywikibot.handleArgs():
        print arg
        if arg == "-interwiki":
            interwiki = True
        elif arg.startswith("-keepname"):
            keep_name = True
        elif arg.startswith("-tolang:"):
            targetLang = arg[8:]
        elif arg.startswith("-tofamily:"):
            targetFamily = arg[10:]
        elif arg.startswith("-file"):
            if len(arg) == 5:
                filename = pywikibot.input(u"Please enter the list's filename: ")
            else:
                filename = arg[6:]
            gen = pagegenerators.TextfilePageGenerator(filename)
        else:
            pageTitle.append(arg)

    if not gen:
        # if the page title is given as a command line argument,
        # connect the title's parts with spaces
        if pageTitle != []:
            pageTitle = " ".join(pageTitle)
            page = pywikibot.Page(pywikibot.getSite(), pageTitle)
        # if no page title was given as an argument, and none was
        # read from a file, query the user
        if not page:
            pageTitle = pywikibot.input(u"Which page to check:")
            page = pywikibot.Page(pywikibot.getSite(), pageTitle)
            # generator which will yield only a single Page
        gen = iter([page])

    if not targetLang and not targetFamily:
        targetSite = pywikibot.getSite("commons", "commons")
    else:
        if not targetLang:
            targetLang = None  # pywikibot.getSite().language
        if not targetFamily:
            targetFamily = None  # pywikibot.getSite().family
        targetSite = pywikibot.getSite(targetLang, targetFamily)
    bot = ImageTransferBot(gen, interwiki=interwiki, targetSite=targetSite, keep_name=keep_name)
    bot.run()
コード例 #11
0
ファイル: reflinks.py プロジェクト: edgarskos/pywikipedia-git
def main():
    genFactory = pagegenerators.GeneratorFactory()

    PageTitles = []
    xmlFilename = None
    always = False
    ignorepdf = False
    limit = None
    namespaces = []
    generator = None
    for arg in pywikibot.handleArgs():
        if arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[11:]))
            except ValueError:
                namespaces.append(arg[11:])
        elif arg.startswith('-summary:'):
            pywikibot.setAction(arg[9:])
        elif arg == '-always':
            always = True
        elif arg == '-ignorepdf':
            ignorepdf= True
        elif arg.startswith('-limit:'):
            limit = int(arg[7:])
        elif arg.startswith('-xmlstart'):
            if len(arg) == 9:
                xmlStart = pywikibot.input(
                    u'Please enter the dumped article to start with:')
            else:
                xmlStart = arg[10:]
        elif arg.startswith('-xml'):
            if len(arg) == 4:
                xmlFilename = pywikibot.input(
                    u'Please enter the XML dump\'s filename:')
            else:
                xmlFilename = arg[5:]
        else:
            genFactory.handleArg(arg)

    if xmlFilename:
        try:
            xmlStart
        except NameError:
            xmlStart = None
        generator = XmlDumpPageGenerator(xmlFilename, xmlStart, namespaces)
    if not generator:
        generator = genFactory.getCombinedGenerator()
    if not generator:
        # syntax error, show help text from the top of this file
        pywikibot.showHelp('reflinks')
        return
    generator = pagegenerators.PreloadingGenerator(generator, pageNumber = 50)
    generator = pagegenerators.RedirectFilterPageGenerator(generator)
    bot = ReferencesRobot(generator, always, limit, ignorepdf)
    bot.run()
コード例 #12
0
def main():
    # if -file is not used, this temporary array is used to read the page title.
    pageTitle = []
    page = None
    gen = None
    interwiki = False
    keep_name = False
    targetLang = None
    targetFamily = None

    for arg in pywikibot.handleArgs():
        if arg == '-interwiki':
            interwiki = True
        elif arg.startswith('-keepname'):
            keep_name = True
        elif arg.startswith('-tolang:'):
            targetLang = arg[8:]
        elif arg.startswith('-tofamily:'):
            targetFamily = arg[10:]
        elif arg.startswith('-file'):
            if len(arg) == 5:
                filename = pywikibot.input(
                    u'Please enter the list\'s filename: ')
            else:
                filename = arg[6:]
            gen = pagegenerators.TextfilePageGenerator(filename)
        else:
            pageTitle.append(arg)

    if not gen:
        # if the page title is given as a command line argument,
        # connect the title's parts with spaces
        if pageTitle != []:
            pageTitle = ' '.join(pageTitle)
            page = pywikibot.Page(pywikibot.getSite(), pageTitle)
        # if no page title was given as an argument, and none was
        # read from a file, query the user
        if not page:
            pageTitle = pywikibot.input(u'Which page to check:')
            page = pywikibot.Page(pywikibot.getSite(), pageTitle)
            # generator which will yield only a single Page
        gen = iter([page])

    if not targetLang and not targetFamily:
        targetSite = pywikibot.getSite('commons', 'commons')
    else:
        if not targetLang:
            targetLang = pywikibot.getSite().language
        if not targetFamily:
            targetFamily = pywikibot.getSite().family
        targetSite = pywikibot.Site(targetLang, targetFamily)
    bot = ImageTransferBot(gen, interwiki=interwiki, targetSite=targetSite,
                           keep_name=keep_name)
    bot.run()
コード例 #13
0
def main():

    pywikibot.warning(u"This script will set preferences on all " u"configured accounts!")
    pywikibot.output(
        u"You have %s accounts configured." % sum([len(family) for family in config.usernames.itervalues()])
    )

    if pywikibot.inputChoice(u"Do you wish to continue?", ["no", "yes"], ["n", "y"], "n") == "n":
        return

    if (
        pywikibot.inputChoice(
            u"Do you already know which preference you wish " u"to set?", ["no", "yes"], ["n", "y"], "y"
        )
        == "n"
    ):
        site = pywikibot.getSite()
        pywikibot.output(u"Getting list of available preferences from %s." % site)
        prefs = Preferences(site)

        pywikibot.output(u"-" * 73)
        pywikibot.output(u"| Name                | Value                    |")
        pywikibot.output(u"-" * 73)
        pref_data = prefs.items()
        pref_data.sort()
        for key, value in pref_data:
            pywikibot.output(table_cell(key, 4) + table_cell(value, 5) + "|")
        pywikibot.output(u"-" * 73)
    pywikibot.output(u"")
    pywikibot.output(u"(For checkboxes: An empty string evaluates to False; " u"all others to True)")
    pywikibot.output(u"")

    while True:
        keys, values = [], []
        while True:
            try:
                keys.append(pywikibot.input(u"Which preference do you wish to set?"))
            except KeyboardInterrupt:
                return
            values.append(pywikibot.input(u"To what value do you wish to set '%s'?" % keys[-1]))
            if pywikibot.inputChoice(u"Set more preferences?", ["no", "yes"], ["n", "y"], "n") == "n":
                break

        if (
            pywikibot.inputChoice(
                u"Set %s?" % u", ".join(u"%s:%s" % (key, value) for key, value in zip(keys, values)),
                ["yes", "no"],
                ["y", "n"],
                "n",
            )
            == "y"
        ):
            set_all(keys, values, verbose=True)
            pywikibot.output(u"Preferences have been set on all wikis.")
コード例 #14
0
def main():
    start = '!'
    featured = False
    title = None
    namespace = None
    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 wikipedia.handleArgs():
        if arg == '-featured':
            featured = True
        elif arg.startswith('-page'):
            if len(arg) == 5:
                title = wikipedia.input(u'Which page should be processed?')
            else:
                title = arg[6:]
        elif arg.startswith('-namespace'):
            if len(arg) == 10:
                namespace = int(wikipedia.input(u'Which namespace should be processed?'))
            else:
                namespace = int(arg[11:])
        else:
            genFactory.handleArg(arg)

    gen = genFactory.getCombinedGenerator()

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

    linktrail = mysite.linktrail()
    if featured:
        featuredList = wikipedia.translate(mysite, featured_articles)
        ref = wikipedia.Page(wikipedia.getSite(), featuredList)
        gen = pagegenerators.ReferringPageGenerator(ref)
        generator = pagegenerators.NamespaceFilterPageGenerator(gen, [0])
        for page in generator:
            workon(page)
    elif title is not None:
        page = wikipedia.Page(wikipedia.getSite(), title)
        workon(page)
    elif namespace is not None:
        for page in pagegenerators.AllpagesPageGenerator(start=start, namespace=namespace, includeredirects=False):
            workon(page)
    elif gen:
        for page in pagegenerators.PreloadingGenerator(gen):
            workon(page)
    else:
        wikipedia.showHelp('fixing_redirects')
コード例 #15
0
ファイル: navy_bot.py プロジェクト: bymerej/ts-multichill-bot
def main(args):
    """
    Main loop.
    """
    start_id = 0
    end_id = 80000
    single_id = 0
    latest = False
    updaterun = False
    site = wikipedia.getSite("commons", "commons")
    updatePage = wikipedia.Page(site, u"User:BotMultichillT/Navy_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.startswith("-id"):
            if len(arg) == 3:
                single_id = wikipedia.input(u"What is the id of the photo you want to transfer?")
            else:
                single_id = arg[4:]
        elif arg == u"-latest":
            latest = True
        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:]

    if single_id > 0:
        processPhoto(photo_id=int(single_id))
    elif latest:
        processLatestPhotos()
    else:
        if updaterun:
            start_id = int(updatePage.get())
            end_id = start_id + int(interval)

        last_id = processPhotos(int(start_id), int(end_id))

        if updaterun:
            comment = u"Worked from " + str(start_id) + u" to " + str(last_id)
            updatePage.put(str(last_id), comment)
コード例 #16
0
ファイル: preferences.py プロジェクト: pywikibot/compat
def main():

    pywikibot.warning(u'This script will set preferences on all '
                     u'configured accounts!')
    pywikibot.output(u'You have %s accounts configured.'
                     % sum([len(family)
                            for family in config.usernames.itervalues()]))

    if pywikibot.inputChoice(u'Do you wish to continue?',
                             ['no', 'yes'], ['n', 'y'], 'n') == 'n':
        return

    if pywikibot.inputChoice(u'Do you already know which preference you wish '
                             u'to set?', ['no', 'yes'], ['n', 'y'], 'y') == 'n':
        site = pywikibot.getSite()
        pywikibot.output(u'Getting list of available preferences from %s.'
                         % site)
        prefs = Preferences(site)

        pywikibot.output(u'-' * 73)
        pywikibot.output(u'| Name                | Value                    |')
        pywikibot.output(u'-' * 73)
        pref_data = prefs.items()
        pref_data.sort()
        for key, value in pref_data:
            pywikibot.output(table_cell(key, 4) + table_cell(value, 5) + '|')
        pywikibot.output(u'-' * 73)
    pywikibot.output(u'')
    pywikibot.output(u'(For checkboxes: An empty string evaluates to False; '
                     u'all others to True)')
    pywikibot.output(u'')

    while True:
        keys, values = [], []
        while True:
            try:
                keys.append(pywikibot.input(
                    u'Which preference do you wish to set?'))
            except KeyboardInterrupt:
                return
            values.append(pywikibot.input(
                u"To what value do you wish to set '%s'?" % keys[-1]))
            if pywikibot.inputChoice(u"Set more preferences?",
                                     ['no', 'yes'], ['n', 'y'], 'n') == 'n':
                break

        if pywikibot.inputChoice(
                u"Set %s?"
                % u', '.join(u'%s:%s' % (key, value)
                             for key, value in zip(keys, values)),
                ['yes', 'no'], ['y', 'n'], 'n') == 'y':
            set_all(keys, values, verbose=True)
            pywikibot.output(u"Preferences have been set on all wikis.")
コード例 #17
0
 def askForCaptcha(self, url):
     try:
         import webbrowser
         wikipedia.output(u'Opening CAPTCHA in your web browser...')
         if webbrowser.open(url):
             return wikipedia.input(u'What is the solution of the CAPTCHA that is shown in your web browser?')
         else:
             raise
     except:
         wikipedia.output(u'Error in opening web browser: %s' % sys.exc_info()[0])
         wikipedia.output(u'Please copy this url to your web browser and open it:\n %s' % url)
         return wikipedia.input(u'What is the solution of the CAPTCHA at this url ?')
コード例 #18
0
def addCoords(sourceWiki, lang, article, lat, lon, region, type, dim):
    '''
    Add the coordinates to article.
    '''

    if (article and lang and type):
        coordTemplate = 'Coordinate'
        site = wikipedia.getSite(lang, 'wikipedia')

        page = wikipedia.Page(site, article)
        try:
            text = page.get()
        except wikipedia.NoPage: # First except, prevent empty pages
            logging.warning('Page empty: %s', article)
            return False
        except wikipedia.IsRedirectPage: # second except, prevent redirect
            logging.warning('Page is redirect: %s', article)
            wikipedia.output(u'%s is a redirect!' % article)
            return False
        except wikipedia.Error: # third exception, take the problem and print
            logging.warning('Some error: %s', article)
            wikipedia.output(u"Some error, skipping..")
            return False       
    
        if coordTemplate in page.templates():
            logging.info('Already has Coordinate template: %s', article)
            return False

        if 'Linn' in page.templates():
            logging.info('Linn template without coords: %s', article)
            return False
            
        newtext = text
        replCount = 1
        coordText = u'{{Coordinate |NS=%s |EW=%s |type=%s |region=%s' % (lat, lon, type, region)
        if (dim):
            coordText += u' |dim=%s' % ( int(dim),)
        coordText += '}}'
        localCatName = wikipedia.getSite().namespace(WP_CATEGORY_NS)
        catStart = r'\[\[(' + localCatName + '|Category):'
        catStartPlain = u'[[' + localCatName + ':'
        replacementText = u''
        replacementText = coordText + '\n\n' + catStartPlain
    
        # insert coordinate template before categories
        newtext = re.sub(catStart, replacementText, newtext, replCount, flags=re.IGNORECASE)

        if text != newtext:
            logging.info('Adding coords to: %s', article)
            comment = u'lisan artikli koordinaadid %s.wikist' % (sourceWiki)
            wikipedia.showDiff(text, newtext)
            modPage = wikipedia.input(u'Modify page: %s ([y]/n) ?' % (article) )
            if (modPage.lower == 'y' or modPage == ''):
                page.put(newtext, comment)
            return True
        else:
            logging.info('Nothing to change: %s', article)
            return False
    else:
        return False
コード例 #19
0
    def run(self):
        for page in self.generator:
            if self.interwiki:
                imagelist = []
                for linkedPage in page.interwiki():
                    imagelist += linkedPage.imagelinks(followRedirects=True)
            elif page.isImage():
                imagePage = pywikibot.ImagePage(page.site(), page.title())
                imagelist = [imagePage]
            else:
                imagelist = page.imagelinks(followRedirects = True)

            while len(imagelist)>0:
                self.showImageList(imagelist)
                if len(imagelist) == 1:
                    # no need to query the user, only one possibility
                    todo = 0
                else:
                    pywikibot.output(
                        u"Give the number of the image to transfer.")
                    todo = pywikibot.input(u"To end uploading, press enter:")
                    if not todo:
                        break
                    todo = int(todo)
                if todo in range(len(imagelist)):
                    if imagelist[todo].fileIsOnCommons():
                        pywikibot.output(
                            u'The image is already on Wikimedia Commons.')
                    else:
                        self.transferImage(imagelist[todo], debug = False)
                    # remove the selected image from the list
                    imagelist = imagelist[:todo] + imagelist[todo + 1:]
                else:
                    pywikibot.output(u'No such image number.')
コード例 #20
0
ファイル: pagegenerators.py プロジェクト: janoszen/sicekit
def TextfilePageGenerator(filename=None, site=None):
    """
    Read a file of page links between double-square-brackets or, in
    alternative, separated by newlines, and return them as a list of Page
    objects. filename is the name of the file that should be read. If no
    name is given, the generator prompts the user.
    """
    if filename is None:
        filename = wikipedia.input(u"Please enter the filename:")
    if site is None:
        site = wikipedia.getSite()
    f = codecs.open(filename, "r", config.textfile_encoding)
    R = re.compile(ur"\[\[(.+?)(?:\]\]|\|)")  # title ends either before | or before ]]
    pageTitle = None
    for pageTitle in R.findall(f.read()):
        # If the link doesn't refer to this site, the Page constructor
        # will automatically choose the correct site.
        # This makes it possible to work on different wikis using a single
        # text file, but also could be dangerous because you might
        # inadvertently change pages on another wiki!
        yield wikipedia.Page(site, pageTitle)
    if pageTitle is None:
        f.seek(0)
        for title in f:
            title = title.strip()
            if title:
                yield wikipedia.Page(site, title)
    f.close()
コード例 #21
0
ファイル: tvpmelder.py プロジェクト: nlwikibots/nlwikibots
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()
コード例 #22
0
ファイル: nps.py プロジェクト: filbertkm/toolserver
	def setMetadata(self):
 		if self.metadata['description'] == None:
			self.metadata['description'] = wikipedia.input("Enter description: ")

		self.metadata['template'] = '== {{int:filedesc}} ==\n{{Information\n|description={{en|1=%s}}\n|date=23 August 2011\n|source=http://www.nps.gov/wamo/photosmultimedia/index.htm \n|author=National Park Service\n|permission=See below}}\n\n== {{int:license}} ==\n{{PD-USGov-NPS}}\n\n[[Category:2011 Virginia earthquake]]\n[[Category:Washington Monument]]' % (self.metadata['description'])

		print self.metadata['template']
コード例 #23
0
ファイル: spellcheck.py プロジェクト: VisualEffects/pywikia
def getalternatives(string):
    # Find possible correct words for the incorrect word string
    basetext = wikipedia.input(u"Give a text that should occur in the words to be checked.\nYou can choose to give no text, but this will make searching slow:")
    basetext = basetext.lower()
    simwords = {}
    for i in xrange(11):
        simwords[i] = []
    for alt in knownwords.keys():
        if basetext:
            if basetext not in alt.lower() == -1:
                dothis = False
            else:
                dothis = True
        else: dothis = True
        if dothis:
            diff = distance(string,alt)
            if diff < 11:
                if knownwords[alt] == alt:
                    simwords[diff] += [alt]
                else:
                    simwords[diff] += knownwords[alt]
    posswords = []
    for i in xrange(11):
        if not simwords[i] in posswords:
            posswords += simwords[i]
    return posswords[:30]
コード例 #24
0
ファイル: pagegenerators.py プロジェクト: dbow/Project-OPEN
def TextfilePageGenerator(filename=None, site=None):
    """Iterate pages from a list in a text file.

    The file must contain page links between double-square-brackets or, in
    alternative, separated by newlines, and return them as a list of Page
    objects. The generator will yield each corresponding Page object.

    @param filename: the name of the file that should be read. If no name is
                     given, the generator prompts the user.
    @param site: the default Site for which Page objects should be created

    """
    if filename is None:
        filename = pywikibot.input(u'Please enter the filename:')
    if site is None:
        site = pywikibot.getSite()
    f = codecs.open(filename, 'r', config.textfile_encoding)
    R = re.compile(ur'\[\[(.+?)(?:\]\]|\|)') # title ends either before | or before ]]
    pageTitle = None
    for pageTitle in R.findall(f.read()):
        # If the link doesn't refer to this site, the Page constructor
        # will automatically choose the correct site.
        # This makes it possible to work on different wikis using a single
        # text file, but also could be dangerous because you might
        # inadvertently change pages on another wiki!
        yield pywikibot.Page(site, pageTitle)
    if pageTitle is None:
        f.seek(0)
        for title in f:
            title = title.strip()
            if '|' in title:
                title = title[:title.index('|')]
            if title:
                yield pywikibot.Page(site, title)
    f.close()
コード例 #25
0
ファイル: editarticle.py プロジェクト: quaasi/pywikipediabot
 def setpage(self):
     """Sets page and page title"""
     site = pywikibot.getSite()
     pageTitle = self.options.page or pywikibot.input(u"Page to edit:")
     self.page = pywikibot.Page(site, pageTitle)
     if not self.options.edit_redirect and self.page.isRedirectPage():
         self.page = self.page.getRedirectTarget()
コード例 #26
0
ファイル: catall.py プロジェクト: yknip1207/genewiki
def choosecats(pagetext):
    chosen=[]
    flag=False
    length=1000
    print ("Give the new categories, one per line.")
    print ("Empty line: if the first, don't change. Otherwise: Ready.")
    print ("-: I made a mistake, let me start over.")
    print ("?: Give the text of the page with GUI.")
    print ("??: Give the text of the page in console.")
    print ("xx: if the first, remove all categories and add no new.")
    print ("q: quit.")
    while flag == False:
        choice=pywikibot.input(u"?")
        if choice=="":
            flag=True
        elif choice=="-":
            chosen=choosecats(pagetext)
            flag=True
        elif choice=="?":
            import editarticle
            editor = editarticle.TextEditor()
            newtext = editor.edit(pagetext)
        elif choice =="??":
            pywikibot.output(pagetext[0:length])
            length = length+500
        elif choice=="xx" and chosen==[]:
            chosen = None
            flag=True
        elif choice=="q":
            print "quit..."
            sys.exit()
        else:
            chosen.append(choice)
    return chosen
コード例 #27
0
ファイル: harvest_template.py プロジェクト: pywikibot/compat
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()
コード例 #28
0
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())
コード例 #29
0
ファイル: login.py プロジェクト: carriercomm/sicekit
    def login(self, api = config.use_api_login, retry = False):
        if not self.password:
            # As we don't want the password to appear on the screen, we set
            # password = True
            self.password = wikipedia.input(u'Password for user %s on %s:' % (self.username, self.site), password = True)

        self.password = self.password.encode(self.site.encoding())

        wikipedia.output(u"Logging in to %s as %s" % (self.site, self.username))
        try:
            cookiedata = self.getCookie(api = api)
        except NotImplementedError:
            wikipedia.output('API disabled because this site does not support.')
            config.use_api_login = api = False
            cookiedata = self.getCookie(api = api)
        if cookiedata:
            self.storecookiedata(cookiedata)
            wikipedia.output(u"Should be logged in now")
            # Show a warning according to the local bot policy
            if not self.botAllowed():
                wikipedia.output(u'*** Your username is not listed on [[%s]].\n*** Please make sure you are allowed to use the robot before actually using it!' % botList[self.site.family.name][self.site.lang])
            return True
        else:
            wikipedia.output(u"Login failed. Wrong password or CAPTCHA answer?")
            if api:
                wikipedia.output(u"API login failed, retrying using standard webpage.")
                return self.login(api = False, retry = retry)
            
            if retry:
                self.password = None
                return self.login(api = api, retry = True)
            else:
                return False
コード例 #30
0
ファイル: image.py プロジェクト: Rodehi/GFROS
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()
コード例 #31
0
def main():
    summary_commandline, gen, template = None, None, None
    namespaces, PageTitles, exceptions = [], [], []
    encat = ''
    autoText, autoTitle = False, False
    recentcat, newcat = False, False
    genFactory = pagegenerators.GeneratorFactory()
    for arg in wikipedia.handleArgs():
        if arg == '-autotitle':
            autoTitle = True
        elif arg == '-autotext':
            autoText = True
        elif arg.startswith('-except:'):
            exceptions.append(arg[8:])

        elif arg.startswith('-start'):
            firstPageTitle = arg[7:]
            if not firstPageTitle:
                firstPageTitle = wikipedia.input(
                    u'At which page do you want to start?')
            firstPageTitle = wikipedia.Page(
                fasite, firstPageTitle).title(withNamespace=False)
            gen = pagegenerators.AllpagesPageGenerator(firstPageTitle,
                                                       0,
                                                       includeredirects=True)
        elif arg.startswith('-template:'):
            template = arg[10:]
        elif arg.startswith('-namespace:'):
            namespaces.append(int(arg[11:]))
        elif arg.startswith('-summary:'):
            wikipedia.setAction(arg[9:])
            summary_commandline = True
        else:
            generator = genFactory.handleArg(arg)
            if generator:
                gen = generator
    if not gen:
        wikipedia.stopme()
        sys.exit()
    if namespaces != []:
        gen = pagegenerators.PreloadingGenerator(gen, pageNumber=60)
        preloadingGen = pagegenerators.NamespaceFilterPageGenerator(
            gen, namespaces)
    else:
        preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber=60)
    _cache, last_timestamp = get_cache()
    add_text(preloadingGen)

    now = str(datetime.now())
    todaynum = int(now.split('-')[2].split(' ')[0]) + int(
        now.split('-')[1]) * 30 + (int(now.split('-')[0]) - 2000) * 365

    if last_timestamp + 3 < todaynum:
        put_cache(_cache, todaynum)
    else:
        put_cache({}, 0)
コード例 #32
0
ファイル: login.py プロジェクト: moleculea/ess
    def login(self, api=config.use_api_login, retry=False):
        if not self.password:
            # As we don't want the password to appear on the screen, we set
            # password = True
            self.password = pywikibot.input(
                u'Password for user %(name)s on %(site)s:' % {
                    'name': self.username,
                    'site': self.site
                },
                password=True)

        self.password = self.password.encode(self.site.encoding())

        if api:
            pywikibot.output(u"Logging in to %(site)s as %(name)s via API." % {
                'name': self.username,
                'site': self.site
            })
        else:
            pywikibot.output(u"Logging in to %(site)s as %(name)s" % {
                'name': self.username,
                'site': self.site
            })

        try:
            cookiedata = self.getCookie(api)
        except NotImplementedError:
            pywikibot.output(
                'API disabled because this site does not support.\nRetrying by ordinary way...'
            )
            api = False
            return self.login(False, retry)
        if cookiedata:
            fn = '%s-%s-%s-login.data' % (self.site.family.name,
                                          self.site.lang, self.username)
            #self.storecookiedata(fn,cookiedata)
            pywikibot.output(u"Should be logged in now")
            # Show a warning according to the local bot policy
            if not self.botAllowed():
                pywikibot.output(
                    u'*** Your username is not listed on [[%s]].\n*** Please make sure you are allowed to use the robot before actually using it!'
                    % botList[self.site.family.name][self.site.lang])
            return True
        else:
            pywikibot.output(
                u"Login failed. Wrong password or CAPTCHA answer?")
            if api:
                pywikibot.output(
                    u"API login failed, retrying using standard webpage.")
                return self.login(False, retry)

            if retry:
                self.password = None
                return self.login(api, True)
            else:
                return False
コード例 #33
0
 def __init__(self,
              query=None,
              count=100,
              site=None):  # values larger than 100 fail
     self.query = query or wikipedia.input(
         u'Please enter the search query:')
     self.count = count
     if site is None:
         site = wikipedia.getSite()
     self.site = site
コード例 #34
0
 def askForCaptcha(self, url):
     """Show the user a CAPTCHA image and return the answer."""
     try:
         import webbrowser
         wikipedia.output(u'Opening CAPTCHA in your web browser...')
         if webbrowser.open(url):
             return wikipedia.input(
                 u'What is the solution of the CAPTCHA that is shown in '
                 u'your web browser?')
         else:
             raise
     except:
         wikipedia.output(u'Error in opening web browser: %s' %
                          sys.exc_info()[0])
         wikipedia.output(
             u'Please copy this url to your web browser and open it:\n %s' %
             url)
         return wikipedia.input(
             u'What is the solution of the CAPTCHA at this url ?')
コード例 #35
0
def main():
    import wikipedia, config

    wikipedia.output(u'Warning! This script will set preferences on all configured accounts!')
    wikipedia.output(u'You have %s accounts configured.' % \
        sum([len(family) for family in config.usernames.itervalues()]))

    if wikipedia.inputChoice(u'Do you wish to continue?', ['no', 'yes'], ['n', 'y'], 'n') == 'n': return

    if wikipedia.inputChoice(u'Do you already know which preference you wish to set?',
            ['no', 'yes'], ['n', 'y'], 'y') == 'n':
        site = wikipedia.getSite()
        wikipedia.output(u'Getting list of available preferences from %s.' % site)
        prefs = Preferences(site)

        wikipedia.output(u'-------------------------------------------------------------------------')
        wikipedia.output(u'| Name                | Value                    |')
        wikipedia.output(u'-------------------------------------------------------------------------')
        pref_data = prefs.items()
        pref_data.sort()
        for key, value in pref_data:
            wikipedia.output(table_cell(key, 4) + table_cell(value, 5) + '|')
        wikipedia.output(u'-------------------------------------------------------------------------')
    wikipedia.output(u'')
    wikipedia.output(u'(For checkboxes: An empty string evaluates to False; all others to True)')
    wikipedia.output(u'')

    while True:
        keys, values = [], []
        while True:
            try:
                keys.append(wikipedia.input(u'Which preference do you wish to set?'))
            except KeyboardInterrupt:
                return
            values.append(wikipedia.input(u"To what value do you wish to set '%s'?" % keys[-1]))
            if wikipedia.inputChoice(u"Set more preferences?",
                    ['no', 'yes'], ['n', 'y'], 'n') == 'n': break

        if wikipedia.inputChoice(u"Set %s?" % u', '.join((u'%s:%s' % (key, value)
                for key, value in zip(keys, values))),
                ['yes', 'no'], ['y', 'n'], 'n') == 'y':
            set_all(keys, values, verbose = True)
            wikipedia.output(u"Preferences have been set on all wikis.")
コード例 #36
0
 def process_filename(self):
     # Isolate the pure name
     filename = self.url
     
     if '/' in filename:
         filename = filename.split('/')[-1]
     
     if '\\' in filename:
         filename = filename.split('\\')[-1]
     
     if self.urlEncoding:
         filename = urllib.unquote(filename.decode(self.urlEncoding))
     
     if self.useFilename:
         filename = self.useFilename
     if not self.keepFilename:
         wikipedia.output(u"The filename on the target wiki will default to: %s" % filename)
         # ask newfn until it's valid
         ok = False
         # FIXME: these 2 belong somewhere else, presumably in family
         forbidden = '/' # to be extended
         allowed_formats = (u'gif', u'jpg', u'jpeg', u'mid', u'midi', u'ogg', u'png', u'svg', u'xcf', u'djvu')
         while not ok:
             ok = True
             newfn = wikipedia.input(u'Enter a better name, or press enter to accept:')
             if newfn == "":
                 newfn = filename
             ext = os.path.splitext(newfn)[1].lower().strip('.')
             for c in forbidden:
                 if c in newfn:
                     print "Invalid character: %s. Please try again" % c
                     ok = False
             if ext not in allowed_formats and ok:
                 choice = wikipedia.inputChoice(u"File format is not one of [%s], but %s. Continue?" % (u' '.join(allowed_formats), ext), ['yes', 'no'], ['y', 'N'], 'N')
                 if choice == 'n':
                     ok = False
         if newfn != '':
             filename = newfn
     # MediaWiki doesn't allow spaces in the file name.
     # Replace them here to avoid an extra confirmation form
     filename = filename.replace(' ', '_')
     # A proper description for the submission.
     wikipedia.output(u"The suggested description is:")
     wikipedia.output(self.description)
     if self.verifyDescription:
             newDescription = u''
             choice = wikipedia.inputChoice(u'Do you want to change this description?', ['Yes', 'No'], ['y', 'N'], 'n')
             if choice == 'y':
                     import editarticle
                     editor = editarticle.TextEditor()
                     newDescription = editor.edit(self.description)
             # if user saved / didn't press Cancel
             if newDescription:
                     self.description = newDescription
     return filename
コード例 #37
0
def main():
    # this temporary array is used to read the page title.
    pageTitle = []
    gen = None

    for arg in sys.argv[1:]:
        arg = wikipedia.argHandler(arg, 'windows_chars')
        if arg:
            if arg.startswith('-file'):
                if len(arg) == 5:
                    filename = wikipedia.input(
                        u'please enter the list\'s filename: ')
                else:
                    filename = arg[6:]
                gen = pagegenerators.TextfilePageGenerator(filename)
            elif arg.startswith('-sql'):
                if len(arg) == 4:
                    sqlfilename = wikipedia.input(
                        u'please enter the SQL dump\'s filename: ')
                else:
                    sqlfilename = arg[5:]
                gen = SqlWindows1252PageGenerator(sqlfilename)
            else:
                pageTitle.append(arg)

    # if a single page is given as a command line argument,
    # reconnect the title's parts with spaces
    if pageTitle != []:
        page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
        gen = iter([page])

    # get edit summary message
    wikipedia.setAction(wikipedia.translate(wikipedia.getSite(), msg))

    if not gen:
        wikipedia.showHelp('windows_chars')
    elif wikipedia.getSite().encoding() == "utf-8":
        print "There is no need to run this robot on UTF-8 wikis."
    else:
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = WindowsCharsBot(preloadingGen)
        bot.run()
コード例 #38
0
    def _show_warning(self):
        """Show compat deprecation waring once."""
        pywikibot.input("""\03{lightyellow}
PLEASE NOTE: compat pywikibot branch is deprecated. You may use it but no
bug fixes, features or support is provided by the pywikibot developer
team anymore.

This package only runs for MediaWiki versions not higher than 1.27.

Please use the new core branch of the pywikibot framework which supports
the current version of MediaWiki. Compat scripts are already migrated
to core branch and there is a migrating tool which helps converting of
your private scripts.

Please refer to:
    http://www.mediawiki.org/wiki/Manual:Pywikibot
    https://phabricator.wikimedia.org/T99365

Press <enter> to continue.
\03{default}""")
コード例 #39
0
def main(*args):
    global catDB
    global logger
    fromGiven = False
    toGiven = False
    batchMode = False
    editSummary = ''
    inPlace = False
    overwrite = False
    showImages = False
    talkPages = False
    recurse = False
    withHistory = False
    titleRegex = None
    pagesonly = 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()
    # The generator gives the pages that should be worked upon.
    gen = None

    # If this is set to true then the custom edit summary given for removing
    # categories from articles will also be used as the deletion reason.
    useSummaryForDeletion = True
    catDB = CategoryDatabase()
    action = None
    sort_by_last_name = False
    restore = False
    create_pages = False
    action = 'listify'
    for arg in pywikibot.handleArgs(*args):
        if arg.startswith('-from:'):
            oldCatTitle = arg[len('-from:'):].replace('_', ' ')
            fromGiven = True
    if action == 'listify':
        if (fromGiven == False):
            oldCatTitle = pywikibot.input(
                u'Please enter the name of the category to listify:')
        newCatTitle = "User:HasteurBot/Log"
        recurse = True
        logger.info('Starting Nudge run over %s' % oldCatTitle)
        bot = CategoryListifyRobot(oldCatTitle,
                                   newCatTitle,
                                   editSummary,
                                   overwrite,
                                   showImages,
                                   subCats=True,
                                   talkPages=talkPages,
                                   recurse=recurse)
        bot.run()
    else:
        pywikibot.showHelp('category')
コード例 #40
0
 def replace(self, rep):
     # Replace the short form by 'rep'. Keeping simple for now - if the
     # short form is part of the long form, replace it. If it is not, ask
     # the user
     if rep == self.derive():
         return self.word
     if self.derive() not in self.word:
         return pywikibot.input(
             u"Please give the result of replacing %s by %s in %s:" %
             (self.derive(), rep, self.word))
     return self.word.replace(self.derive(), rep)
コード例 #41
0
ファイル: intersect_categories.py プロジェクト: xqt/toollabs
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)
コード例 #42
0
def main(args):
    '''
    Main loop.
    '''
    start_id = 0
    end_id = 45000
    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:]

    processPhotos(int(start_id), int(end_id))
コード例 #43
0
ファイル: table2wiki.py プロジェクト: vmorrisonwood/pywikia
    def treat(self, page):
        '''
        Loads a page, converts all HTML tables in its text to wiki syntax,
        and saves the converted text.
        Returns True if the converted table was successfully saved, otherwise
        returns False.
        '''
        wikipedia.output(u'\n>>> %s <<<' % page.title())
        site = page.site()
        try:
            text = page.get()
        except wikipedia.NoPage:
            wikipedia.output(u"ERROR: couldn't find %s" % page.title())
            return False
        except wikipedia.IsRedirectPage:
            wikipedia.output(u'Skipping redirect %s' % page.title())
            return False
        newText, convertedTables, warningSum = self.convertAllHTMLTables(text)

        # Check if there are any marked tags left
        markedTableTagR = re.compile("<##table##|</##table##>", re.IGNORECASE)
        if markedTableTagR.search(newText):
            wikipedia.output(
                u'ERROR: not all marked table start or end tags processed!')
            return

        if convertedTables == 0:
            wikipedia.output(u"No changes were necessary.")
        else:
            if config.table2wikiAskOnlyWarnings and warningSum == 0:
                doUpload = True
            else:
                if config.table2wikiSkipWarnings:
                    doUpload = True
                else:
                    print "There were %i replacement(s) that might lead to bad output." % warningSum
                    doUpload = (wikipedia.input(
                        u'Do you want to change the page anyway? [y|N]') == "y"
                                )
            if doUpload:
                # get edit summary message
                if warningSum == 0:
                    wikipedia.setAction(
                        wikipedia.translate(site.lang, msg_no_warnings))
                elif warningSum == 1:
                    wikipedia.setAction(
                        wikipedia.translate(site.lang, msg_one_warning) %
                        warningSum)
                else:
                    wikipedia.setAction(
                        wikipedia.translate(site.lang, msg_multiple_warnings) %
                        warningSum)
                page.put_async(newText)
コード例 #44
0
def main():
    site = wikipedia.getSite()
    roadnumber = 419
    loopsat = True
 
    for arg in wikipedia.handleArgs():
        if arg.startswith('-road'):
            if len(arg) == 5:
                roadnumber = int(wikipedia.input('What road do you want to start at?'))
            elif len(arg) > 5:
                roadnumber = int(arg[6:])
 
    while loopsat == True:
        if roadnumber >= 1000:
            return
        listpage = wikipedia.Page(site, "List of highways numbered %s" % str(roadnumber))
        if listpage.exists() == True:
            wikipedia.setAction("Robot: Making redirects for Wikiproject U.S. Roads")
            wikipedia.output(">List of highways numbered %s exists" % str(roadnumber))
            rd = "#REDIRECT [[List of highways numbered %s]]" % str(roadnumber)
            p1 = wikipedia.Page(site, "Route %s" % str(roadnumber))
            p2 = wikipedia.Page(site, "Highway %s" % str(roadnumber))
            p3 = wikipedia.Page(site, "State Route %s" % str(roadnumber))
            p4 = wikipedia.Page(site, "State Highway %s" % str(roadnumber))
            p5 = wikipedia.Page(site, "State Road %s" % str(roadnumber))
            p6 = wikipedia.Page(site, "SR_%s" % str(roadnumber))
            p7 = wikipedia.Page(site, "SH_%s" % str(roadnumber))
            p8 = wikipedia.Page(site, "SR-%s" % str(roadnumber))
            p9 = wikipedia.Page(site, "SH-%s" % str(roadnumber))
            p10 = wikipedia.Page(site, "Federal Highway %s" % str(roadnumber))
            p11 = wikipedia.Page(site, "National Highway %s" % str(roadnumber))
            p12 = wikipedia.Page(site, "Federal Road %s" % str(roadnumber))
            p13 = wikipedia.Page(site, "National Road %s" % str(roadnumber))
            p14 = wikipedia.Page(site, "Federal Route %s" % str(roadnumber))
            p15 = wikipedia.Page(site, "National Route %s" % str(roadnumber))
            p16 = wikipedia.Page(site, "SR%s" % str(roadnumber))
            p17 = wikipedia.Page(site, "SH%s" % str(roadnumber))
            pagelist = [p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17]
 
            for i in pagelist:
                if i.exists() == False:
                    wikipedia.output(">>Creating %s" % i.title() )
                    i.put(rd)
                else:
                    wikipedia.output(">>%s exists" % i.title() )
        else:
            wikipedia.output(">List of highways numbered %s does not exist" % str(roadnumber))
        #End Of Loop
        roadnumber = roadnumber + 1
    wikipedia.output("Done!")
コード例 #45
0
ファイル: category.py プロジェクト: willend/SASfit
 def run(self):
     self.newcatTitle = pywikibot.input(
         u'Category to add (do not give namespace):')
     if not self.site.nocapitalize:
         self.newcatTitle = self.newcatTitle[:1].upper() + \
                            self.newcatTitle[1:]
     if not self.editSummary:
         self.editSummary = i18n.twtranslate(self.site, 'category-adding',
                                             {'newcat': self.newcatTitle})
     counter = 0
     for page in self.generator:
         self.treat(page)
         counter += 1
     pywikibot.output(u"%d page(s) processed." % counter)
コード例 #46
0
    def treat(self, page):
        '''
        Loads a page, converts all HTML tables in its text to wiki syntax,
        and saves the converted text. Returns True if the converted table was
        successfully saved, otherwise returns False.
        '''
        pywikibot.output(u'\n>>> %s <<<' % page.title())
        site = page.site()
        try:
            text = page.get()
        except pywikibot.NoPage:
            pywikibot.error(u"couldn't find %s" % page.title())
            return False
        except pywikibot.IsRedirectPage:
            pywikibot.output(u'Skipping redirect %s' % page.title())
            return False
        newText, convertedTables, warningSum = self.convertAllHTMLTables(text)

        # Check if there are any marked tags left
        markedTableTagR = re.compile("<##table##|</##table##>", re.IGNORECASE)
        if markedTableTagR.search(newText):
            pywikibot.error(
                u'not all marked table start or end tags processed!')
            return

        if convertedTables == 0:
            pywikibot.output(u"No changes were necessary.")
        else:
            if config.table2wikiAskOnlyWarnings and warningSum == 0:
                doUpload = True
            else:
                if config.table2wikiSkipWarnings:
                    doUpload = True
                else:
                    print(
                        "There were %i replacement(s) that might lead to bad "
                        "output.") % warningSum
                    doUpload = (pywikibot.input(
                        u'Do you want to change the page anyway? [y|N]') == "y"
                                )
            if doUpload:
                # get edit summary message
                if warningSum == 0:
                    pywikibot.setAction(
                        i18n.twtranslate(site.lang, 'table2wiki-no-warning'))
                else:
                    pywikibot.setAction(
                        i18n.twntranslate(site.lang, 'table2wiki-warnings',
                                          {'count': warningSum}))
                page.put_async(newText)
コード例 #47
0
ファイル: commonscat.py プロジェクト: XXN/pywikibot-compat
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
    """
    summary = None
    generator = None
    always = False
    ns = []
    ns.append(14)

    # Process global args and prepare generator args parser

    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs(*args):
        if 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('-checkcurrent'):
            primaryCommonscat, commonscatAlternatives = \
                CommonscatBot.getCommonscatTemplate(
                    pywikibot.getSite().language())
            generator = pagegenerators.NamespaceFilterPageGenerator(
                pagegenerators.ReferringPageGenerator(
                    pywikibot.Page(pywikibot.getSite(),
                                   u'Template:' + primaryCommonscat),
                    onlyTemplateInclusion=True), ns)

        elif arg == '-always':
            always = True
        else:
            genFactory.handleArg(arg)

    if not generator:
        generator = genFactory.getCombinedGenerator()

    if generator:
        pregenerator = pagegenerators.PreloadingGenerator(generator)
        bot = CommonscatBot(pregenerator, always, summary)
        bot.run()
    else:
        pywikibot.showHelp()
コード例 #48
0
ファイル: Scotland_lists.py プロジェクト: xqt/toollabs
def main(*args):
    dblocation = u''
    for arg in pywikibot.handleArgs(*args):
        if arg.startswith('-db:'):
            if len(arg) == 4:
                dblocation = pywikibot.input(
                    u'Please enter the location of the database')
            else:
                dblocation = arg[4:]
    if not dblocation:
        usage()
        return
        
    db = dbf.Dbf(dblocation, readOnly=1)
    procesDB(db)
コード例 #49
0
    def getReasonForDeletion(self, page):
        suggestedReason = self.guessReasonForDeletion(page)
        wikipedia.output(
            u'The suggested reason is: \03{lightred}%s\03{default}' %
            suggestedReason)

        # We don't use wikipedia.translate() here because for some languages the
        # entry is intentionally left out.
        if self.mySite.family.name in self.delete_reasons:
            if page.site().lang in self.delete_reasons[
                    self.mySite.family.name]:
                localReasons = wikipedia.translate(page.site().lang,
                                                   self.delete_reasons)
                wikipedia.output(u'')
                localReasoneKey = localReasons.keys()
                localReasoneKey.sort()
                for key in localReasoneKey:
                    wikipedia.output((key + ':').ljust(8) + localReasons[key])
                wikipedia.output(u'')
                reason = wikipedia.input(
                    u'Please enter the reason for deletion, choose a default reason, or press enter for the suggested message:'
                )
                if reason.strip() in localReasons:
                    reason = localReasons[reason]
            else:
                reason = wikipedia.input(
                    u'Please enter the reason for deletion, or press enter for the suggested message:'
                )
        else:
            reason = wikipedia.input(
                u'Please enter the reason for deletion, or press enter for the suggested message:'
            )

        if not reason:
            reason = suggestedReason
        return reason
コード例 #50
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 wikipedia.handleArgs():
        if arg.startswith('-xml'):
            if len(arg) == 4:
                xmlFilename = wikipedia.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 = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
        gen = iter([page])
    if not gen:
        gen = genFactory.getCombinedGenerator()
    if not gen:
        wikipedia.showHelp('noreferences')
    else:
        if namespaces != []:
            gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
        preloadingGen = pagegenerators.PreloadingGenerator(gen)
        bot = NoReferencesBot(preloadingGen, always)
        bot.run()
コード例 #51
0
    def getCategoryGen(self, arg, length, recurse=False):
        site = wikipedia.getSite()
        if len(arg) == length:
            categoryname = wikipedia.input(u'Please enter the category name:')
        else:
            categoryname = arg[length + 1:]

        ind = categoryname.find('|')
        startfrom = None
        if ind > 0:
            startfrom = categoryname[ind + 1:]
            categoryname = categoryname[:ind]

        cat = catlib.Category(site,
                              "%s:%s" % (site.namespace(14), categoryname))
        return CategorizedPageGenerator(cat, start=startfrom, recurse=recurse)
コード例 #52
0
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())
コード例 #53
0
    def setSubCategoriesGen(self, arg, length, recurse = False):
        site = pywikibot.getSite()
        if len(arg) == length:
            categoryname = pywikibot.input(u'Please enter the category name:')
        else:
            categoryname = arg[length + 1:]

        ind = categoryname.find('|')
        if ind > 0:
            startfrom = categoryname[ind + 1:]
            categoryname = categoryname[:ind]
        else:
            startfrom = None

        cat = catlib.Category(site,
                              "%s:%s" % (site.namespace(14), categoryname))
        return SubCategoriesPageGenerator(cat, start=startfrom, recurse=recurse)
コード例 #54
0
def main():
    username = password = None
    sysop = False
    logall = False
    forceLogin = False
    verbose = False

    for arg in wikipedia.handleArgs():
        if arg.startswith("-pass"):
            if len(arg) == 5:
                password = wikipedia.input(u'Password for all accounts:', password = True)
            else:
                password = arg[6:]
        elif arg == "-sysop":
            sysop = True
        elif arg == "-all":
            logall = True
        elif arg == "-force":
            forceLogin = True
        else:
            wikipedia.showHelp('login')
            return
    
    if wikipedia.verbose > 1:
      wikipedia.output(u"WARNING: Using -v -v on login.py might leak private data. When sharing, please double check your password is not readable and log out your bots session.")
      verbose = True # only use this verbose when running from login.py
    if logall:
        if sysop:
            namedict = config.sysopnames
        else:
            namedict = config.usernames
        for familyName in namedict.iterkeys():
            for lang in namedict[familyName].iterkeys():
                try:
                    site = wikipedia.getSite( code=lang, fam=familyName )
                    if not forceLogin and site.loggedInAs(sysop = sysop) is not None:
                        wikipedia.output(u'Already logged in on %s' % site)
                    else:
                        loginMan = LoginManager(password, sysop = sysop, site = site, verbose=verbose)
                        loginMan.login()
                except wikipedia.NoSuchSite:
                    wikipedia.output(lang+ u'.' + familyName + u' is not a valid site, please remove it from your config')

    else:
        loginMan = LoginManager(password, sysop = sysop, verbose=verbose)
        loginMan.login()
コード例 #55
0
def main():
    '''
    Parse the command line arguments and get a pagegenerator to work on.
    Iterate through all the pages.
    '''
    summary = None
    generator = None
    checkcurrent = False
    always = False
    ns = []
    ns.append(14)
    # Load a lot of default generators
    genFactory = pagegenerators.GeneratorFactory()

    for arg in pywikibot.handleArgs():
        if 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('-checkcurrent'):
            checkcurrent = True
            primaryCommonscat, commonscatAlternatives = \
                               CommonscatBot.getCommonscatTemplate(
                                   pywikibot.getSite().language())
            generator = pagegenerators.NamespaceFilterPageGenerator(
                pagegenerators.ReferringPageGenerator(
                    pywikibot.Page(pywikibot.getSite(),
                                   u'Template:' + primaryCommonscat),
                    onlyTemplateInclusion=True), ns)

        elif arg == '-always':
            always = True
        else:
            genFactory.handleArg(arg)

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

    pregenerator = pagegenerators.PreloadingGenerator(generator)
    bot = CommonscatBot(pregenerator, always, summary)
    bot.run()
コード例 #56
0
ファイル: commonscat.py プロジェクト: vmorrisonwood/pywikia
def main():
    '''
    Parse the command line arguments and get a pagegenerator to work on.
    Iterate through all the pages.
    '''
    summary = None; generator = None; checkcurrent = False; always = False
    ns = []
    ns.append(14)
    # Load a lot of default generators
    genFactory = pagegenerators.GeneratorFactory()

    for arg in wikipedia.handleArgs():
        if arg.startswith('-summary'):
            if len(arg) == 8:
                summary = wikipedia.input(u'What summary do you want to use?')
            else:
                summary = arg[9:]
        elif arg.startswith('-checkcurrent'):
            checkcurrent = True
            primaryCommonscat, commonscatAlternatives = getCommonscatTemplate(wikipedia.getSite().language())
            generator = pagegenerators.NamespaceFilterPageGenerator(pagegenerators.ReferringPageGenerator(wikipedia.Page(wikipedia.getSite(), u'Template:' + primaryCommonscat), onlyTemplateInclusion=True), ns)

        elif arg == '-always':
            always = True
        else:
            genFactory.handleArg(arg)

    if not generator:
        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)

    for page in pregenerator:
        if not page.exists():
           wikipedia.output(u'Page %s does not exist. Skipping.' % page.aslink())
        elif page.isRedirectPage():
           wikipedia.output(u'Page %s is a redirect. Skipping.' % page.aslink())
        elif page.isCategoryRedirect():
           wikipedia.output(u'Page %s is a category redirect. Skipping.' % page.aslink())
        elif page.isDisambig():
           wikipedia.output(u'Page %s is a disambiguation. Skipping.' % page.aslink())
        else:
            (status, always) = addCommonscat(page, summary, always)
コード例 #57
0
def main():
    start = '!'
    featured = False
    namespace = None
    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 wikipedia.handleArgs():
        if arg == '-featured':
            featured = True
        elif arg.startswith('-namespace'):
            if len(arg) == 10:
                namespace = int(wikipedia.input(u'Which namespace should be processed?'))
            else:
                namespace = int(arg[11:])
        else:
            genFactory.handleArg(arg)

    gen = genFactory.getCombinedGenerator()

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

    linktrail = mysite.linktrail()
    if featured:
        featuredList = wikipedia.translate(mysite, featured_articles)
        ref = wikipedia.Page(wikipedia.getSite(), featuredList)
        gen = pagegenerators.ReferringPageGenerator(ref)
        generator = pagegenerators.NamespaceFilterPageGenerator(gen, [0])
        for page in generator:
            workon(page)
    elif namespace is not None:
        for page in pagegenerators.AllpagesPageGenerator(start=start, namespace=namespace, includeredirects=False):
            workon(page)
    elif gen:
        for page in pagegenerators.PreloadingGenerator(gen):
            workon(page)
    else:
        wikipedia.showHelp('fixing_redirects')
コード例 #58
0
ファイル: i18n.py プロジェクト: dysklyver/pywikipediabot
def input(twtitle, parameters=None, password=False):
    """ Ask the user a question, return the user's answer.
        @param twtitle The TranslateWiki string title, in <package>-<key> format
        @param parameters For passing parameters. In the future, this will
                          be used for plural support.
        @param password Hides the user's input (for password entry)
        Returns a unicode string

        The translations are retrieved from i18n.<package>, based on the callers
        import table.
        Translation code should be set by in the user_config.py like
        userinterface_lang = 'de'
        default is mylang setting

    """
    code = config.userinterface_lang or config.mylang
    trans = twtranslate(code, twtitle, parameters)
    return pywikibot.input(trans, password)
コード例 #59
0
ファイル: getimages.py プロジェクト: dysklyver/pywikipediabot
def main():
    for filename in getfn():
        print "Handling images from %s" % filename
        gen = pagegenerators.TextfilePageGenerator(filename)
        for image in gen:
            if image.isImage():
                print "-" * 50
                print "Image: %s" % image.title()
                try:
                    # show the image description page's contents
                    print image.get()
                except wikipedia.NoPage:
                    print "Description empty."
                except wikipedia.IsRedirectPage:
                    print "Description page is redirect?!"
                answer=wikipedia.input(u"Copy this image (y/N)?")
                if answer.lower().startswith('y'):
                    lib_images.transfer_image(image)
コード例 #60
0
def main(your_page):
    screen = False # If True it would not edit the wiki, only output statistics
    _page = None

    pywikibot.output("\nBuilding the bot...")
    for arg in pywikibot.handleArgs():    # Parse command line arguments
        if arg.startswith('-page'):
            if len(arg) == 5:
                _page = pywikibot.input(u'On what page do you want to add statistics?')
            else:
                _page = arg[6:]
        if arg.startswith("-screen"):
            screen = True
    if not _page:
        _page = your_page
        if not screen:
            pywikibot.output("The bot will add statistics on %s.\n" % _page )
    bot = StatisticsBot(screen, _page) # Launch the instance of a StatisticsBot
    bot.run() # Execute the 'run' method