def main(): genFactory = pagegenerators.GeneratorFactory() # The generator gives the pages that should be worked upon. gen = None pageTitleParts = [] for arg in pywikibot.handleArgs(): if arg.startswith("-reg"): arg = '-transcludes:Infobox film' if not genFactory.handleArg(arg): pageTitleParts.append(arg) if pageTitleParts != []: # We will only work on a single page. pageTitle = ' '.join(pageTitleParts) page = pywikibot.Page(pywikibot.getSite(), pageTitle) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) bot = FilmBannerBot(gen) bot.run() else: pywikibot.showHelp()
def main(): wikipedia.setSite(wikipedia.getSite(u'commons', u'commons')) # Connect database, we need that conn = None cursor = None (conn, cursor) = connectDatabase() generator = None genFactory = pagegenerators.GeneratorFactory() for arg in wikipedia.handleArgs(): genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator() if not generator: generator = getRijksmonumentWithoutLocation() # Get a preloading generator with only images pgenerator = pagegenerators.PreloadingGenerator( pagegenerators.NamespaceFilterPageGenerator(generator, [6])) for page in pgenerator: locationTemplate = locateImage(page, conn, cursor) if locationTemplate: addLocation(page, locationTemplate)
def main(*args): try: genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(*args): if not genFactory.handleArg(arg): pywikibot.showHelp() break else: gen = genFactory.getCombinedGenerator() if gen: page_match = re.compile('\{\{AFC submission\|') summary = u"[[User:HasteurBot|HasteurBot Task 3]]: Removing " + \ u"maint category that does not apply" disclude_list = [ u'Wikipedia talk:WikiProject Articles for creation', u'Wikipedia talk:WikiProject Articles for creation/2013 5', u'Wikipedia talk:WikiProject Articles for creation/2011', ] for article in gen: if article.title() in disclude_list: continue art_text = article.get() if page_match.match(art_text) is not None: print article art_1 = re.sub( '\\\n\[\[\:Category\:AfC_submissions_with_missing_AfC_template\]\]', '', art_text) art_2 = re.sub( '\\\n\[\[\:Category\:AfC submissions with missing AfC template\]\]', '', art_1) article.put(art_2, comment=summary) else: pywikibot.showHelp() finally: pywikibot.stopme()
def main(args): """ Grab a bunch of images and tag them if they are not categorized. """ generator = None genFactory = pagegenerators.GeneratorFactory() site = pywikibot.getSite(u'commons', u'commons') pywikibot.setSite(site) for arg in pywikibot.handleArgs(): if arg.startswith('-yesterday'): generator = uploadedYesterday(site) elif arg.startswith('-recentchanges'): generator = recentChanges(site=site, delay=120) else: genFactory.handleArg(arg) if not generator: generator = genFactory.getCombinedGenerator() if not generator: pywikibot.output(u'You have to specify the generator you want to use ' u'for the program!') else: pregenerator = pagegenerators.PreloadingGenerator(generator) for page in pregenerator: if page.exists() and (page.namespace() == 6) \ and (not page.isRedirectPage()): if isUncat(page): addUncat(page)
def main(args): ''' Main loop. Get a generator and options. Work on all images in the generator. ''' generator = None onlyFilter = False onlyUncat = False genFactory = pagegenerators.GeneratorFactory() global search_wikis global hint_wiki site = pywikibot.getSite(u'commons', u'commons') pywikibot.setSite(site) for arg in pywikibot.handleArgs(): if arg == '-onlyfilter': onlyFilter = True elif arg == '-onlyuncat': onlyUncat = True elif arg.startswith('-hint:'): hint_wiki = arg [len('-hint:'):] elif arg.startswith('-onlyhint'): search_wikis = arg [len('-onlyhint:'):] else: genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator() if not generator: generator = pagegenerators.CategorizedPageGenerator( catlib.Category(site, u'Category:Media needing categories'), recurse=True) initLists() categorizeImages(generator, onlyFilter, onlyUncat) pywikibot.output(u'All done')
def main(*args): # Disable cosmetic changes because we don't want to modify any page # content, so that we don't flood the histories with minor changes. config.cosmetic_changes = False #page generator gen = None genFactory = pagegenerators.GeneratorFactory() redirs = False # If the user chooses to work on a single page, this temporary array is # used to read the words from the page title. The words will later be # joined with spaces to retrieve the full title. pageTitle = [] for arg in pywikibot.handleArgs(*args): if genFactory.handleArg(arg): continue if arg == '-redir': redirs = True else: pageTitle.append(arg) gen = genFactory.getCombinedGenerator() if not gen: if pageTitle: # work on a single page page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle)) gen = iter([page]) else: pywikibot.showHelp() return preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = TouchBot(preloadingGen, redirs) bot.run()
def main(): #page generator gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitle = [] # Which namespaces should be processed? # default to [] which means all namespaces will be processed namespaces = [] # Never ask before changing a page always = False # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg.startswith('-xml'): if len(arg) == 4: xmlFilename = i18n.input('pywikibot-enter-xml-filename') else: xmlFilename = arg[5:] gen = XmlDumpNoReferencesPageGenerator(xmlFilename) elif arg.startswith('-namespace:'): try: namespaces.append(int(arg[11:])) except ValueError: namespaces.append(arg[11:]) elif arg == '-always': always = True else: if not genFactory.handleArg(arg): pageTitle.append(arg) if pageTitle: page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle)) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if not gen: site = pywikibot.getSite() try: cat = maintenance_category[site.family.name][site.lang] except: pass else: import catlib if not namespaces: namespaces = [0] cat = catlib.Category(site, "%s:%s" % (site.category_namespace(), cat)) gen = pagegenerators.CategorizedPageGenerator(cat) if not gen: pywikibot.showHelp('noreferences') else: if namespaces: gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces) preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = NoReferencesBot(preloadingGen, always) bot.run()
def main(): #page generator gen = None # If the user chooses to work on a single page, this temporary array is # used to read the words from the page title. The words will later be # joined with spaces to retrieve the full title. pageTitle = [] # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if not genFactory.handleArg(arg): pageTitle.append(arg) if pageTitle: # work on a single page page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle)) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if not gen: pywikibot.showHelp('inline_images') else: preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = InlineImagesRobot(preloadingGen) bot.run()
def main(): wikipedia.output(u'Testing 1 2 3') generator = None genFactory = pagegenerators.GeneratorFactory() site = wikipedia.getSite(u'commons', u'commons') wikipedia.setSite(site) for arg in wikipedia.handleArgs(): if arg.startswith('-page'): if len(arg) == 5: generator = [ wikipedia.Page( site, wikipedia.input(u'What page do you want to use?')) ] else: generator = [wikipedia.Page(site, arg[6:])] else: generator = genFactory.handleArg(arg) if generator: for page in generator: if (page.namespace() == 14): sort_TOL_Category(catlib.Category(site, page.title())) else: wikipedia.output(u'No categories to work on!')
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()
def main(args): ''' Main loop. Get a generator and options. ''' generator = None parent = u'' basename = u'' always = False genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg == '-always': always = True elif arg.startswith('-parent:'): parent = arg [len('-parent:'):].strip() elif arg.startswith('-basename'): basename = arg [len('-basename:'):].strip() else: genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator() if generator: for page in generator: createCategory(page, parent, basename) else: pywikibot.output(u'No pages to work on') pywikibot.output(u'All done')
def Manual_main(): wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay() gen= None word=u'' PageTitles = [] genFactory = pagegenerators.GeneratorFactory() for arg in wikipedia.handleArgs(): if arg.startswith( '-page' ): PageTitles.append( arg[6:] ) break else: generator = genFactory.handleArg( arg ) if generator: gen = generator if PageTitles: pages = [wikipedia.Page(wikipedia.getSite(),PageTitle) for PageTitle in PageTitles] gen = iter( pages ) if not gen: wikipedia.stopme() sys.exit() preloadingGen = pagegenerators.PreloadingGenerator(gen,pageNumber = 60) for faTitle in preloadingGen: wikipedia.output(u'---'+faTitle.title()+u'-----') OurResult=main(faTitle.title(),word) OurResult=Open_json(OurResult,faTitle.title()) if OurResult.strip(): wikipedia.output(OurResult) with codecs.open(BotAdress_main+u'zz_most_miss_result.txt' ,mode = 'a',encoding = 'utf8' ) as f: f.write(OurResult.strip()+u'\n') with codecs.open(BotAdress_main+u'zz_most_miss_result_number.txt' ,mode = 'a',encoding = 'utf8' ) as f: f.write(OurResult.split(u'@')[0].strip()+u'\n')
def main(): bot = None action = None # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() gen = None for arg in wikipedia.handleArgs(): if action == None: action = arg else: generator = genFactory.handleArg(arg) if generator: gen = generator if action == 'export': if gen == None: wikipedia.output( u'\03{lightred}Export bot needs a page generator to itterate over.\03{default}' ) return bot = GEExport(gen) elif action == 'import': bot = GEImport() if bot == None: wikipedia.output( u'\03{lightred}Invalid bot action to run.\03{default}') return bot.run()
def main(): featured = False gen = None # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg == '-featured': featured = True else: genFactory.handleArg(arg) mysite = pywikibot.getSite() if mysite.sitename() == 'wikipedia:nl': pywikibot.output( u'\03{lightred}There is consensus on the Dutch Wikipedia that bots should not be used to fix redirects.\03{default}' ) sys.exit() if featured: featuredList = pywikibot.translate(mysite, featured_articles) ref = pywikibot.Page(pywikibot.getSite(), featuredList) gen = pagegenerators.ReferringPageGenerator(ref) gen = pagegenerators.NamespaceFilterPageGenerator(gen, [0]) if not gen: gen = genFactory.getCombinedGenerator() if gen: for page in pagegenerators.PreloadingGenerator(gen): workon(page) else: pywikibot.showHelp('fixing_redirects')
def main(): # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() # The generator gives the pages that should be worked upon. gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitleParts = [] # Parse command line arguments for arg in pywikibot.handleArgs(): if arg.startswith("-reg"): arg = '-cat:Unassessed film articles' if not genFactory.handleArg(arg): pageTitleParts.append(arg) if pageTitleParts != []: # We will only work on a single page. pageTitle = ' '.join(pageTitleParts) page = pywikibot.Page(pywikibot.getSite(), pageTitle) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator( filmfunctions.PagesFromTalkPagesGenerator(gen)) bot = FilmAssessBot(gen) bot.run() else: pywikibot.showHelp()
def main(args): pywikibot.output(u'WARNING: This is an experimental bot') pywikibot.output( u'WARNING: It will only work on self published work images') pywikibot.output(u'WARNING: This bot is still full of bugs') pywikibot.output(u'WARNING: Use at your own risk!') generator = None autonomous = False checkTemplate = True # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg == '-nochecktemplate': checkTemplate = False elif arg == '-autonomous': autonomous = True else: genFactory.handleArg(arg) if not supportedSite(): pywikibot.output(u'Sorry, this site is not supported (yet).') return False generator = genFactory.getCombinedGenerator() if not generator: raise add_text.NoEnoughData( 'You have to specify the generator you want to use for the script!' ) pregenerator = pagegenerators.PreloadingGenerator(generator) prefetchQueue = Queue(maxsize=50) uploadQueue = Queue(maxsize=200) imageFetcherThread = imageFetcher(pregenerator, prefetchQueue) userInteractionThread = userInteraction(prefetchQueue, uploadQueue) uploaderThread = uploader(uploadQueue) imageFetcherThread.daemon = False userInteractionThread.daemon = False uploaderThread.daemon = False if autonomous: pywikibot.output( u'Bot is running in autonomous mode. There will be no user interaction.' ) userInteractionThread.setAutonomous() if not checkTemplate: pywikibot.output( u'No check template will be added to the uploaded files.') uploaderThread.nochecktemplate() fetchDone = imageFetcherThread.start() userDone = userInteractionThread.start() uploadDone = uploaderThread.start()
def main(): #page generator gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitle = [] # Which namespaces should be processed? # default to [] which means all namespaces will be processed namespaces = [] # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() always = False for arg in pywikibot.handleArgs(): if arg.startswith('-xml'): if len(arg) == 4: xmlFilename = pywikibot.input( u'Please enter the XML dump\'s filename:') else: xmlFilename = arg[5:] gen = XmlDumpSelflinkPageGenerator(xmlFilename) elif arg == '-sql': # NOT WORKING YET query = """ SELECT page_namespace, page_title FROM page JOIN pagelinks JOIN text ON (page_id = pl_from AND page_id = old_id) WHERE pl_title = page_title AND pl_namespace = page_namespace AND page_namespace = 0 AND (old_text LIKE concat('%[[', page_title, ']]%') OR old_text LIKE concat('%[[', page_title, '|%')) LIMIT 100""" gen = pagegenerators.MySQLPageGenerator(query) elif arg.startswith('-namespace:'): try: namespaces.append(int(arg[11:])) except ValueError: namespaces.append(arg[11:]) elif arg == '-always': always = True else: if not genFactory.handleArg(arg): pageTitle.append(arg) if pageTitle: page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle)) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if not gen: pywikibot.showHelp('selflink') else: if namespaces != []: gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces) preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = SelflinkBot(preloadingGen, always) bot.run()
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"
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)
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)
def main(): # HACK: This can be removed when pywikipedia bug 3315395 has been fixed safetyLock = 'birthcat-unlock.dat' if not os.path.exists(safetyLock): choice = pywikibot.inputChoice( u'Have you patched textlib.py in pywikipedia?', ['Yes', 'No'], ['y', 'N'], 'N') if choice == 'y': open(safetyLock, 'w').close() else: return False # END OF HACK # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() # The generator gives the pages that should be worked upon. gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitleParts = [] # If dry is True, doesn't do any real changes, but only show # what would have been changed. dry = False # If auto is True, run in autonomous mode. auto = False # Parse command line arguments for arg in pywikibot.handleArgs(): if arg.startswith("-dry"): dry = True elif arg.startswith("-auto"): auto = True else: # check if a standard argument like # -start:XYZ or -ref:Asdf was given. if not genFactory.handleArg(arg): pageTitleParts.append(arg) if pageTitleParts != []: # We will only work on a single page. pageTitle = ' '.join(pageTitleParts) page = pywikibot.Page(pywikibot.getSite(), pageTitle) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) bot = BirthCatBot(gen, auto, dry) bot.run() else: pywikibot.showHelp()
def main(*args): global catDB 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 == 'listify': # action = 'listify' # else: # genFactory.handleArg(arg) if action == 'listify': oldCatTitle = 'test' #if (fromGiven == False): # oldCatTitle = pywikibot.input( # u'Please enter the name of the category to nominate over:') newCatTitle = "User:HasteurBot/Log" recurse = True bot = CategoryListifyRobot(oldCatTitle, newCatTitle, editSummary, overwrite, showImages, subCats=True, talkPages=talkPages, recurse=recurse) bot.run() else: pywikibot.showHelp('category')
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()
def main(): args = wikipedia.handleArgs() all = False genFactory = pagegenerators.GeneratorFactory() for currentArgument in args: if currentArgument.startswith("-always"): all = True else: generator = genFactory.handleArg(currentArgument) # Check if pages on which the bot should work are specified. if not generator: raise Exception('You have to specify which pages the script has to work on!') # Main Loop for i in generator: attenzioneIo = False # Dubbio su "I", che può essere articolo determinativo italiano o pronome personale inglese titolo = i.title() wikipedia.output(">>>>> " + titolo + " <<<<<") nuovoTitolo = re.sub("^(The |A |An |Il |Lo |La |I |Gli |Le |L'|Uno |Una |Un'|Un )([A-Z0-9].*)", r"{{DEFAULTSORT:\2, \1}}", titolo) if titolo == nuovoTitolo: wikipedia.output("Non c'è nessun articolo. Prossima pagina...") continue if re.search("^I ", titolo): attenzioneIo = True nuovoTitolo = re.sub("[ ']\}\}", "}}", nuovoTitolo) # Toglie spazi, apostrofi... try: oldtext = i.get() except wikipedia.IsRedirectPage: wikipedia.output(u"%s is a redirect, I'll ignore it." % i.title()) continue if re.search("\{\{DEFAULTSORT:", oldtext): wikipedia.output("C'è già un DEFAULTSORT. Prossima pagina...") continue newtext = add_text(page = i, addText = nuovoTitolo, putText = False, oldTextGiven = oldtext)[1] wikipedia.showDiff(oldtext, newtext) if not all or attenzioneIo: choice = wikipedia.inputChoice(u"Modificare?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N') else: choice = 'y' if choice in ['A', 'a']: all = True choice = 'y' if choice in ['Y', 'y']: i.put_async(newtext, comment="Aggiungo: " + nuovoTitolo)
def main(): # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() # The generator gives the pages that should be worked upon. gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitleParts = [] # If dry is True, doesn't do any real changes, but only show # what would have been changed. dry = False # will become True when the user uses the -always flag. always = False # will input Yomi data input = False # will input Yomi data outputwiki = False # Parse command line arguments for arg in pywikibot.handleArgs(): if arg.startswith("-dry"): dry = True elif arg.startswith("-always"): always = True elif arg.startswith("-input"): input = True elif arg.startswith("-outputwiki"): outputwiki = True else: # check if a standard argument like # -start:XYZ or -ref:Asdf was given. if not genFactory.handleArg(arg): pageTitleParts.append(arg) if pageTitleParts != []: # We will only work on a single page. pageTitle = ' '.join(pageTitleParts) page = pywikibot.Page(pywikibot.getSite(), pageTitle) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) bot = MuseumCategoryBot(gen, dry, always, input, outputwiki) bot.run() else: pywikibot.showHelp()
def main(): #page generator gen = None pageTitle = [] editSummary = '' answer = 'y' always = False # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg.startswith('-summary:'): editSummary = arg[len('-summary:'):] elif arg == '-always': always = True elif not genFactory.handleArg(arg): pageTitle.append(arg) if editSummary == '': # Load default summary message. editSummary = pywikibot.translate(pywikibot.getSite(), msg_standalone) # Disabled this check. Although the point is still valid, there # is now a warning and a prompt (see below). #if pywikibot.getSite() == pywikibot.getSite('nl','wikipedia'): #print "Deze bot is op WikipediaNL niet gewenst." #print "Het toevoegen van cosmetic changes bij andere wijzigingen is toegestaan," #print "maar cosmetic_changes als stand-alone bot niet." #print "Zoek alstublieft een nuttig gebruik voor uw bot." #sys.exit() if pageTitle: page = pywikibot.Page(pywikibot.getSite(), ' '.join(pageTitle)) gen = iter([page]) if not gen: gen = genFactory.getCombinedGenerator() if not gen: pywikibot.showHelp() elif not always: answer = pywikibot.inputChoice( warning + '\nDo you really want to continue?', ['yes', 'no'], ['y', 'N'], 'N') if answer == 'y': preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CosmeticChangesBot(preloadingGen, acceptall=always, comment=editSummary) bot.run()
def main(): """ Process command line arguments and invoke bot. """ #page generator gen = None # This temporary array is used to read the page title if one single # page to work on is specified by the arguments. pageTitle = [] # Which namespaces should be processed? # default to [] which means all namespaces will be processed namespaces = [] # This factory is responsible for processing command line arguments # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() # Never ask before changing a page always = False to13 = False format = False for arg in pywikibot.handleArgs(): if arg.startswith('-namespace:'): try: namespaces.append(int(arg[11:])) except ValueError: namespaces.append(arg[11:]) elif arg == '-always': always = True elif arg == '-to13': to13 = True elif arg == '-format': format = True else: if not genFactory.handleArg(arg): pageTitle.append(arg) site = pywikibot.getSite() if pageTitle: gen = iter([pywikibot.Page(site, t) for t in pageTitle]) if not gen: gen = genFactory.getCombinedGenerator() if not gen: pywikibot.showHelp('isbn') else: if namespaces != []: gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces) preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = IsbnBot(preloadingGen, to13=to13, format=format, always=always) bot.run()
def main(args): generator = None always = False # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): genFactory.handleArg(arg) 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 page.exists() and (page.namespace() == 6) and \ (not page.isRedirectPage()): imagepage = pywikibot.ImagePage(page.site(), page.title()) foundNowCommons = False for template in imagepage.templates(): #FIXME: Move the templates list to a lib. if template in pywikibot.translate(imagepage.site(), nowCommons): foundNowCommons = True if foundNowCommons: pywikibot.output( u'The file %s is already tagged with NowCommons' % imagepage.title()) else: imagehash = imagepage.getHash() commons = pywikibot.getSite(u'commons', u'commons') duplicates = commons.getFilesFromAnHash(imagehash) if duplicates: duplicate = duplicates.pop() pywikibot.output(u'Found duplicate image at %s' % duplicate) comment = i18n.twtranslate( imagepage.site(), 'commons-file-now-available', { 'localfile': imagepage.titleWithoutNamespace(), 'commonsfile': duplicate }) template = pywikibot.translate(imagepage.site(), nowCommonsTemplate) newtext = imagepage.get() + template % (duplicate, ) pywikibot.showDiff(imagepage.get(), newtext) imagepage.put(newtext, comment)
def main(args): generator = None genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator() if not generator: return False for page in generator: if page.exists() and page.namespace() == 14: filterCategory(page)
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()