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(): """ 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) # Process global args and prepare generator args parser local_args = pywikibot.handleArgs() genFactory = pagegenerators.GeneratorFactory() for arg in local_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'): checkcurrent = True elif arg == '-always': 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 not generator: raise add_text.NoEnoughData(u'You have to specify the generator you ' u'want to use for the script!') pregenerator = pagegenerators.PreloadingGenerator(generator) bot = CommonscatBot(pregenerator, always, summary) bot.run()
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)
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 always = False checkTemplate = True # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg == '-nochecktemplate': checkTemplate = False else: 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) 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 not checkTemplate: uploaderThread.nochecktemplate() fetchDone = imageFetcherThread.start() userDone = userInteractionThread.start() uploadDone = uploaderThread.start()
def main(args): generator = None #newname = ""; imagepage = None always = False category = u'' # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() for arg in pywikibot.handleArgs(): if arg == '-always': always = True elif arg.startswith('-cc:'): category = arg[len('-cc:'):] else: 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: skip = False if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()): imagepage = pywikibot.ImagePage(page.site(), page.title()) #First do autoskip. if doiskip(imagepage.get()): pywikibot.output("Skipping " + page.title()) skip = True else: # The first upload is last in the list. try: username = imagepage.getLatestUploader()[0] except NotImplementedError: #No API, using the page file instead (datetime, username, resolution, size, comment) = imagepage.getFileVersionHistory().pop() if always: newname = imagepage.titleWithoutNamespace() CommonsPage = pywikibot.Page( pywikibot.getSite('commons', 'commons'), u'File:' + newname) if CommonsPage.exists(): skip = True else: while True: # Do the Tkdialog to accept/reject and change te name (newname, skip) = Tkdialog(imagepage.titleWithoutNamespace(), imagepage.get(), username, imagepage.permalink(), imagepage.templates()).getnewname() if skip: pywikibot.output('Skipping this image') break # Did we enter a new name? if len(newname) == 0: #Take the old name newname = imagepage.titleWithoutNamespace() else: newname = newname.decode('utf-8') # Check if the image already exists CommonsPage = pywikibot.Page( pywikibot.getSite('commons', 'commons'), u'File:' + newname) if not CommonsPage.exists(): break else: pywikibot.output( 'Image already exists, pick another name or skip this image' ) # We dont overwrite images, pick another name, go to the start of the loop if not skip: imageTransfer(imagepage, newname, category).start() pywikibot.output(u'Still ' + str(threading.activeCount()) + u' active threads, lets wait') for openthread in threading.enumerate(): if openthread != threading.currentThread(): openthread.join() pywikibot.output(u'All threads are done')