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 """ xmlFilename = None xmlStart = None options = {} generator = None # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg.startswith('-summary:'): options['summary'] = arg[9:] elif arg == '-always': options['always'] = True elif arg == '-ignorepdf': options['ignorepdf'] = True elif arg.startswith('-limit:'): options['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: generator = XmlDumpPageGenerator(xmlFilename, xmlStart, genFactory.namespaces) if not generator: generator = genFactory.getCombinedGenerator() if not generator: pywikibot.bot.suggest_help(missing_generator=True) return False if not genFactory.nopreload: generator = pagegenerators.PreloadingGenerator(generator) generator = pagegenerators.RedirectFilterPageGenerator(generator) bot = ReferencesRobot(generator, **options) bot.run() return True
def generator(self): """Generator method.""" gens = (t.getReferences(follow_redirects=True, namespaces=[6], onlyTemplateInclusion=True) for t in self.nc_templates) gen = chain(*gens) gen = pg.DuplicateFilterPageGenerator(gen) gen = pg.PreloadingGenerator(gen) return gen
def __init__(self, generator): """ Constructor. @param generator: A generator that yields Page objects. """ super(CoordImportRobot, self).__init__() self.generator = pagegenerators.PreloadingGenerator(generator) self.cacheSources() self.prop = 'P625'
def list_template_usage(row_template_name): """Return a generator of main space pages transcluding a given template.""" site = wikipedia.getSite('de', 'wikipedia') rowTemplate = wikipedia.Page( site, u'%s:%s' % (site.namespace(10), row_template_name)) transGen = pagegenerators.ReferringPageGenerator( rowTemplate, onlyTemplateInclusion=True) filteredGen = pagegenerators.NamespaceFilterPageGenerator(transGen, [0]) generator = pagegenerators.PreloadingGenerator(filteredGen) return generator
def setup(self): """Refresh generator.""" generator = pagegenerators.CategorizedPageGenerator( self.csd_cat, start=self.saved_progress) # wrap another generator around it so that we won't produce orphaned # talk pages. generator = pagegenerators.PageWithTalkPageGenerator(generator) self.generator = pagegenerators.PreloadingGenerator(generator, groupsize=20) self.saved_progress = None
def generator(self): """Generator method.""" gens = (t.getReferences(follow_redirects=True, namespaces=[6], only_template_inclusion=True) for t in self.nc_templates) gen = chain(*gens) gen = filter_unique(gen, key=lambda p: '{}:{}:{}'.format(*p._cmpkey())) gen = pg.PreloadingGenerator(gen) return gen
def __init__(self, generator): """ Arguments: * generator - A generator that yields Page objects. """ self.generator = pagegenerators.PreloadingGenerator(generator) self.repo = pywikibot.Site().data_repository() self.cacheSources() self.prop = 'P625'
def main(): xmlFilename = None options = {} namespaces = [] generator = None # Process global args and prepare generator args parser local_args = pywikibot.handleArgs() genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg.startswith('-namespace:'): try: namespaces.append(int(arg[11:])) except ValueError: namespaces.append(arg[11:]) elif arg.startswith('-summary:'): options['summary'] = arg[9:] elif arg == '-always': options['always'] = True elif arg == '-ignorepdf': options['ignorepdf'] = True elif arg.startswith('-limit:'): options['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() return generator = pagegenerators.PreloadingGenerator(generator, step=50) generator = pagegenerators.RedirectFilterPageGenerator(generator) bot = ReferencesRobot(generator, **options) bot.run()
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 """ generator = None local_args = pywikibot.handle_args(args) site = pywikibot.Site() if site.code != 'commons' or site.family.name != 'commons': pywikibot.warning( 'This script is primarily written for Wikimedia ' 'Commons, but has been invoked with site {0}. It ' 'might work for other sites but there is no ' 'guarantee that it does the right thing.'.format(site)) choice = pywikibot.input_choice( 'How do you want to continue?', (('Continue using {0}'.format(site), 'c'), ('Switch to Wikimedia Commons', 's'), ('Quit', 'q')), automatic_quit=False) if choice == 's': site = pywikibot.Site('commons', 'commons') elif choice == 'q': return False genFactory = pagegenerators.GeneratorFactory(site) for arg in local_args: if arg.startswith('-yesterday'): generator = uploadedYesterday(site) elif arg.startswith('-recentchanges'): generator = recentChanges(site=site, delay=120) else: genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator(gen=generator) if not generator: pywikibot.bot.suggest_help(missing_generator=True) return False else: pregenerator = pagegenerators.PreloadingGenerator(generator) site.login() for page in pregenerator: pywikibot.output(page.title()) if page.exists() and (page.namespace() == 6) \ and (not page.isRedirectPage()): if isUncat(page): addUncat(page) return True
def main(): commonssite = pywikibot.Site(u'commons', u'commons') templatepage = pywikibot.Page(commonssite, title=u'Template:RKDimages') gen = pagegenerators.PreloadingGenerator( pagegenerators.NamespaceFilterPageGenerator( pagegenerators.ReferringPageGenerator(templatepage, onlyTemplateInclusion=True), 6)) rkdimagesImporter = RKDImagesImporter(gen) rkdimagesImporter.run()
def main(*args): """Process command line arguments and invoke bot.""" generator = None autonomous = False checkTemplate = True # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() local_args = pywikibot.handle_args(args) for arg in local_args: if arg == '-nochecktemplate': checkTemplate = False elif arg == '-autonomous': autonomous = True else: genFactory.handleArg(arg) generator = genFactory.getCombinedGenerator() if not generator: pywikibot.bot.suggest_help(missing_generator=True) return False if not supportedSite(): pywikibot.output(u'Sorry, this site is not supported (yet).') return False pywikibot.warning(u'This is an experimental bot') pywikibot.warning(u'It will only work on self published work images') pywikibot.warning(u'This bot is still full of bugs') pywikibot.warning(u'Use at your own risk!') 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 ' u'user interaction.') userInteractionThread.setAutonomous() if not checkTemplate: pywikibot.output(u'No check template will be added to the uploaded ' u'files.') uploaderThread.nochecktemplate()
def main(): singlepage = [] gen = None start = None action = None for arg in pywikibot.handleArgs(): if arg == ('pages'): action = 'pages' elif arg == ('categories'): action = 'categories' elif arg.startswith('-start:'): start = pywikibot.Page(pywikibot.Site(), arg[7:]) gen = pagegenerators.AllpagesPageGenerator( start.title(withNamespace=False), namespace=start.namespace(), includeredirects=False) elif arg.startswith('-cat:'): cat = pywikibot.Category(pywikibot.Site(), 'Category:%s' % arg[5:]) gen = pagegenerators.CategorizedPageGenerator(cat) elif arg.startswith('-ref:'): ref = pywikibot.Page(pywikibot.Site(), arg[5:]) gen = pagegenerators.ReferringPageGenerator(ref) elif arg.startswith('-link:'): link = pywikibot.Page(pywikibot.Site(), arg[6:]) gen = pagegenerators.LinkedPageGenerator(link) elif arg.startswith('-page:'): singlepage = pywikibot.Page(pywikibot.Site(), arg[6:]) gen = iter([singlepage]) #else: #bug if action == 'pages': preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CommonsLinkBot(preloadingGen, acceptall=False) bot.pages() elif action == 'categories': preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CommonsLinkBot(preloadingGen, acceptall=False) bot.categories() else: pywikibot.showHelp(u'commons_link')
def run(self): cat = catlib.Category(pywikibot.Link('Category:' + self.catTitle)) articles = set(cat.articles()) if len(articles) == 0: pywikibot.output(u'There are no articles in category ' + catTitle) else: preloadingGen = pagegenerators.PreloadingGenerator(iter(articles)) for article in preloadingGen: pywikibot.output('') pywikibot.output(u'=' * 67) self.move_to_category(article, cat, cat)
def run(self): cat = pywikibot.Category(self.site, self.catTitle) if cat.categoryinfo['pages'] == 0: pywikibot.output(u'There are no articles in category %s' % self.catTitle) else: preloadingGen = pagegenerators.PreloadingGenerator(cat.articles()) for article in preloadingGen: pywikibot.output('') pywikibot.output(u'=' * 67) self.move_to_category(article, cat, cat)
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 """ options = {} # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg.startswith('-summary:'): options['comment'] = arg[len('-summary:'):] elif arg == '-always': options['always'] = True elif arg == '-async': options['async'] = True elif arg.startswith('-ignore:'): ignore_mode = arg[len('-ignore:'):].lower() if ignore_mode == 'method': options['ignore'] = CANCEL_METHOD elif ignore_mode == 'page': options['ignore'] = CANCEL_PAGE else: raise ValueError( 'Unknown ignore mode "{0}"!'.format(ignore_mode)) else: genFactory.handleArg(arg) site = pywikibot.Site() if 'comment' not in options or not options['comment']: # Load default summary message. options['comment'] = i18n.twtranslate(site, 'cosmetic_changes-standalone') gen = genFactory.getCombinedGenerator() if gen: if options.get('always') or pywikibot.input_yn( warning + '\nDo you really want to continue?', default=False, automatic_quit=False): site.login() preloadingGen = pagegenerators.PreloadingGenerator(gen) bot = CosmeticChangesBot(preloadingGen, **options) bot.run() else: pywikibot.showHelp()
def main(): """ main(): Main loop """ lista_images = getCacheDump(config['FILES']['images']) num_fetch_threads = int(config['THREAD']['threads']) cola = Queue(maxsize=int(config['THREAD']['threads'])) for i in range(num_fetch_threads): worker = Thread(target=procesador, args=( cola, i, )) worker.setDaemon(True) worker.start() try: chdir(CWD) except FileNotFoundError: pass printToCsv(line=\ ['Wikipedia', 'Imagen', 'URL Wikipedia', 'URL Q wikidata'],\ archivo=config['FILES']['images']) ##Cleanup if path.isfile(config['FILES']['images']): remove(config['FILES']['images']) saveOldDump() #default cat if config['SITE']['cat'] != '': cat = config['SITE']['cat'] else: cat =\ 'Category:Wikipedia:Artículos con coordenadas en Wikidata' generador = pagegenerators.CategorizedPageGenerator(\ pywikibot.Category(\ pywikibot.Link(cat ))) pages = pagegenerators.PreloadingGenerator(\ generador,\ getLimite(SITE)) #for debug #pages = [pywikibot.Page(source=SITE,title='Þeistareykjarbunga')] lista_cache = getCacheDump(str(config['FILES']['skip'])) for p in pages: if p.title() not in lista_cache: cola.put(p) cola.join() printHtml()
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 """ options = {} generator = None checkcurrent = False ns = [] ns.append(14) # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg.startswith('-summary'): if len(arg) == 8: options['summary'] = pywikibot.input( u'What summary do you want to use?') else: options['summary'] = arg[9:] elif arg.startswith('-checkcurrent'): checkcurrent = True elif arg == '-always': options['always'] = True else: genFactory.handleArg(arg) if checkcurrent: primaryCommonscat, commonscatAlternatives = \ CommonscatBot.getCommonscatTemplate( pywikibot.Site().code) generator = pagegenerators.NamespaceFilterPageGenerator( pagegenerators.ReferringPageGenerator(pywikibot.Page( pywikibot.Site(), u'Template:' + primaryCommonscat), onlyTemplateInclusion=True), ns) if not generator: generator = genFactory.getCombinedGenerator() if generator: pregenerator = pagegenerators.PreloadingGenerator(generator) bot = CommonscatBot(pregenerator, **options) bot.run() else: pywikibot.showHelp()
def _change(self, gen): """Private function to move category contents. Do not use this function from outside the class. @param gen: Generator containing pages or categories. """ for page in pagegenerators.PreloadingGenerator(gen): if not self.title_regex or re.search(self.title_regex, page.title()): page.change_category(self.oldcat, self.newcat, comment=self.comment, inPlace=self.inplace)
def createcategories(addedprojects, debug, commandLogFile): # For tests #addedprojects.append('test_bot') botName=config.usernames['wikipedia']['fr'] pywikibot.output('Create categories') pywikibot.output(str(addedprojects)) site = pywikibot.getSite() addedprojectscat=list() addedprojectscatpage=list() addedprojects.sort() addedprojectscat.append(addedprojects[0]) addedprojectscatpage.append(pywikibot.Page(site, u'Catégorie:Traduction du Projet %s' % addedprojects[0])) for project in addedprojects: if project!=addedprojectscat[-1]: addedprojectscat.append(project) addedprojectscatpage.append(pywikibot.Page(site, u'Catégorie:Traduction du Projet %s' % project)) pywikibot.output('------------------------------') pywikibot.output(str(addedprojectscatpage)) catgenerator=iter(addedprojectscatpage) catpreloadingGen=pagegenerators.PreloadingGenerator(catgenerator, 60) index=0 for addedprojectcatpage in catpreloadingGen: if not addedprojectcatpage.exists(): pywikibot.output(u'%s does not exist' % addedprojectcatpage.title(asLink=True)) title = addedprojectcatpage.title() project = re.search(u'Traduction du Projet (.+)', title).group(1) #project=addedprojectscat[index] main_cat_project = pywikibot.Page(site, u"Catégorie:Projet:%s" % project) main_cat_project_str = '' if main_cat_project.exists(): main_cat_project_str = main_cat_project.title(asLink=True) text=u'{{Translation/Projet|%s}}\n[[Catégorie:Traduction par projet|%s]]\n%s' % (project, project, main_cat_project_str) if (debug==0) or (debug==3): commandLogFile.write(u'******************************** %s ********************************\n' % addedprojectcatpage.title()) commandLogFile.write(text) commandLogFile.write(u'********************************\n') addedprojectcatpage.put(text, u'Catégorisation en projet des pages de traduction') elif debug==2: newpage=pywikibot.Page(site, u'Utilisateur:'+botName+'/Test') newpage.put(text, u'Création de [[:%s]] ([[%s]])' % (addedprojectcatpage.title(), project)) commandLogFile.write(u'* Création de [[:%s]]\r\n' % addedprojectcatpage.title()) index=index+1
def main(*args): """ Process command line arguments and invoke bot. @param args: command line arguments @type args: list of unicode """ options = { 'subject_only': False, 'talk_only': False, 'to_subject': False, 'to_talk': False, } # Process global arguments local_args = pywikibot.handle_args(args) site = pywikibot.Site() site.login() # Parse command line arguments gen_factory = pagegenerators.GeneratorFactory(site) for arg in local_args: if gen_factory.handleArg(arg): continue arg, _, value = arg.partition(':') arg = arg[1:] if arg == 'editnotice_template': if not value: value = pywikibot.input( 'Please enter a value for {}'.format(arg), default=None) options[arg] = value else: options[arg] = True if not validate_options(options, site): pywikibot.error('Invalid options.') return False gen = gen_factory.getCombinedGenerator() if options['to_subject']: gen = page_with_subject_page_generator( gen, return_subject_only=options['subject_only']) elif options['to_talk']: gen = pagegenerators.PageWithTalkPageGenerator( gen, return_talk_only=options['talk_only']) elif options['subject_only']: gen = subject_page_generator(gen) elif options['talk_only']: gen = talk_page_generator(gen) gen = editnotice_page_generator(gen) for key in ('subject_only', 'talk_only', 'to_subject', 'to_talk'): options.pop(key, None) gen = pagegenerators.PreloadingGenerator(gen) EditnoticeDeployer(gen, site=site, **options).run() return True
def main(*args): """ Process command line arguments and invoke bot. If args is an empty list, sys.argv is used. :param args: command line arguments :type args: str """ options = {} gen = None local_args = pywikibot.handle_args(args) # 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. gen_factory = pagegenerators.GeneratorFactory(positional_arg_name='page') for arg in local_args: option, _, value = arg.partition(':') if option == '-xml': filename = value or pywikibot.input( "Please enter the XML dump's filename:") gen = TableXmlDumpPageGenerator(filename) elif option in ['-always', '-quiet', '-skipwarning']: options[option[1:]] = True else: if option == '-mysqlquery': query = value or """ SELECT page_namespace, page_title FROM page JOIN text ON (page_id = old_id) WHERE old_text LIKE '%<table%' """ arg = '-mysqlquery:' + query gen_factory.handle_arg(arg) if gen: gen = pagegenerators.NamespaceFilterPageGenerator( gen, gen_factory.namespaces) else: gen = gen_factory.getCombinedGenerator() if gen: if not gen_factory.nopreload: gen = pagegenerators.PreloadingGenerator(gen) bot = Table2WikiRobot(generator=gen, **options) bot.run() else: suggest_help(missing_generator=True)
def getPageGenerator(self): if self.getOption('use_hash'): gen = self.useHashGenerator() else: gens = [ t.getReferences(follow_redirects=True, namespaces=[6], onlyTemplateInclusion=True) for t in self.nc_templates ] gen = pg.CombinedPageGenerator(gens) gen = pg.DuplicateFilterPageGenerator(gen) gen = pg.PreloadingGenerator(gen) return gen
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 """ options = {} # Process global arguments to determine desired site local_args = pywikibot.handle_args(args) # 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() # Parse command line arguments for arg in local_args: # Catch the pagegenerators options if genFactory.handleArg(arg): continue # nothing to do here # Now pick up your own options arg, sep, value = arg.partition(':') option = arg[1:] if option in ('summary', 'text', 'outpage', 'maxlines', 'listscount', 'testcount', 'skip'): if not value: pywikibot.input('Please enter a value for ' + arg) options[option] = value # take the remaining options as booleans. # You will get a hint if they aren't pre-definded in your bot class else: options[option] = True gen = genFactory.getCombinedGenerator() if gen: # The preloading generator is responsible for downloading multiple # pages from the wiki simultaneously. gen = pagegenerators.PreloadingGenerator(gen) # pass generator and private options to the bot bot = BasicBot(gen, **options) bot.run() # guess what it does return True else: pywikibot.bot.suggest_help(missing_generator=True) return False
def __init__(self, generator, templateTitle, fields): """ Arguments: * generator - A generator that yields Page objects. * templateTitle - The template to work on * fields - A dictionary of fields that are of use to us """ self.generator = pg.PreloadingGenerator(generator) self.templateTitle = templateTitle.replace(u'_', u' ') # TODO: Make it a list which also includes the redirects to the template self.fields = fields self.repo = pywikibot.Site().data_repository() self.cacheSources()
def __init__(self, lang, noclaims, templateclaims): """ Arguments: * lang - The language code of the Wikipedia we're working on * noclaims - The title of the page on Wikidata with the list of pages to work on * templateclaims - The title of the page on Wikipedia with the template claims """ self.lang = lang self.site = pywikibot.Site(self.lang, u'wikipedia') self.repo = self.site.data_repository() self.generator = pg.PreloadingGenerator(pg.NamespaceFilterPageGenerator(self.getNoclaimGenerator(noclaims), 0)) self.templateclaims = templateclaims self.templates = self.getTemplateClaims(templateclaims)
def main(*args): """ Process command line arguments and invoke bot. If args is an empty list, sys.argv is used. @param args: command line arguments @type args: unicode """ options = {} checkcurrent = False # Process global args and prepare generator args parser local_args = pywikibot.handle_args(args) genFactory = pagegenerators.GeneratorFactory() for arg in local_args: if arg.startswith('-summary'): if len(arg) == 8: options['summary'] = pywikibot.input( 'What summary do you want to use?') else: options['summary'] = arg[9:] elif arg.startswith('-checkcurrent'): checkcurrent = True elif arg == '-always': options['always'] = True else: genFactory.handleArg(arg) if checkcurrent: site = pywikibot.Site() primaryCommonscat, commonscatAlternatives = \ CommonscatBot.getCommonscatTemplate( site.code) template_page = pywikibot.Page(site, 'Template:' + primaryCommonscat) generator = template_page.getReferences(namespaces=14, only_template_inclusion=True) else: generator = genFactory.getCombinedGenerator() if generator: if not genFactory.nopreload: generator = pagegenerators.PreloadingGenerator(generator) bot = CommonscatBot(generator, **options) bot.run() return True else: pywikibot.bot.suggest_help(missing_generator=True) return False
def check_hard_redirect(self): """ Check for hard-redirected categories. Check categories that are not already marked with an appropriate softredirect template. """ pywikibot.output("Checking hard-redirect category pages.") comment = i18n.twtranslate(self.site, self.redir_comment) # generator yields all hard redirect pages in namespace 14 for page in pagegenerators.PreloadingGenerator(self.site.allpages( namespace=14, filterredir=True), groupsize=250): if page.isCategoryRedirect(): # this is already a soft-redirect, so skip it (for now) continue try: target = page.getRedirectTarget() except pywikibot.CircularRedirect: target = page self.problems.append(u"# %s is a self-linked redirect" % page.title(asLink=True, textlink=True)) except RuntimeError: # race condition: someone else removed the redirect while we # were checking for it continue if target.isCategory(): # this is a hard-redirect to a category page newtext = (u"{{%(template)s|%(cat)s}}" % { 'cat': target.title(withNamespace=False), 'template': self.template_list[0] }) try: page.text = newtext page.save(comment) self.log_text.append( u"* Added {{tl|%s}} to %s" % (self.template_list[0], page.title(asLink=True, textlink=True))) except pywikibot.Error: self.log_text.append( u"* Failed to add {{tl|%s}} to %s" % (self.template_list[0], page.title(asLink=True, textlink=True))) else: self.problems.append( u"# %s is a hard redirect to %s" % (page.title(asLink=True, textlink=True), target.title(asLink=True, textlink=True)))
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() # 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() site.login() if pageTitle: gen = iter( [pywikibot.Page(pywikibot.Link(t, site)) 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 __init__(self, generator, createnew=False): """ Arguments: * generator - A standard python generator * createnew - Are we creating new items? """ # Do something with filtergenerator and image generator? self.generator = pagegenerators.FileGenerator( pagegenerators.PreloadingGenerator(generator)) self.createnew = createnew self.repo = pywikibot.Site().data_repository() self.paintingIdProperty = 217 self.paintingIds = self.fillCache(self.paintingIdProperty)
def __init__(self): """ Grab generator based on SPARQL to work on. """ self.site = pywikibot.Site(u'commons', u'commons') self.repo = self.site.data_repository() self.search = u'incategory:"Media donated by Naturalis Biodiversity Center" -haswbstatement:P180' self.generator = pagegenerators.PreloadingGenerator( pagegenerators.SearchPageGenerator(self.search, namespaces=6, site=self.site)) self.speciescategories = self.speciesCategoriesOnWikidata()