def refreshGenerator(self): generator = pagegenerators.CategorizedPageGenerator( self.csdCat, start=self.savedProgress) # wrap another generator around it so that we won't produce orphaned talk pages. generator2 = pagegenerators.PageWithTalkPageGenerator(generator) self.preloadingGen = pagegenerators.PreloadingGenerator(generator2, pageNumber=20)
def main(): # If none, the var is setted only for check purpose. summary = None addText = None regexSkip = None regexSkipUrl = None generator = None always = False textfile = None talkPage = False reorderEnabled = True namespaces = [] # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() # Put the text above or below the text? up = False # Loading the arguments for arg in pywikibot.handleArgs(): if arg.startswith('-textfile'): if len(arg) == 9: textfile = pywikibot.input( u'Which textfile do you want to add?') else: textfile = arg[10:] elif arg.startswith('-text'): if len(arg) == 5: addText = pywikibot.input(u'What text do you want to add?') else: addText = 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('-page'): if len(arg) == 5: generator = [pywikibot.Page( pywikibot.getSite(), pywikibot.input(u'What page do you want to use?'))] else: generator = [pywikibot.Page(pywikibot.getSite(), arg[6:])] elif arg.startswith('-excepturl'): if len(arg) == 10: regexSkipUrl = pywikibot.input(u'What text should I skip?') else: regexSkipUrl = arg[11:] elif arg.startswith('-except'): if len(arg) == 7: regexSkip = pywikibot.input(u'What text should I skip?') else: regexSkip = arg[8:] elif arg.startswith('-untagged'): if len(arg) == 9: untaggedProject = pywikibot.input( u'What project do you want to use?') else: untaggedProject = arg[10:] generator = untaggedGenerator(untaggedProject) elif arg == '-up': up = True elif arg == '-noreorder': reorderEnabled = False elif arg == '-always': always = True elif arg == '-talk' or arg == '-talkpage': talkPage = True else: genFactory.handleArg(arg) if textfile and not addText: f = codecs.open(textfile, 'r', config.textfile_encoding) addText = f.read() f.close() if not generator: generator = genFactory.getCombinedGenerator() if not generator: raise NoEnoughData( 'You have to specify the generator you want to use for the script!') if talkPage: generator = pagegenerators.PageWithTalkPageGenerator(generator) site = pywikibot.getSite() for namespace in site.namespaces(): index = site.getNamespaceIndex(namespace) if index % 2 == 1 and index > 0: namespaces += [index] generator = pagegenerators.NamespaceFilterPageGenerator( generator, namespaces) for page in generator: (text, newtext, always) = add_text(page, addText, summary, regexSkip, regexSkipUrl, always, up, True, reorderEnabled=reorderEnabled, create=talkPage)
def main(): # If none, the var is setted only for check purpose. summary = None addText = None regexSkip = None regexSkipUrl = None generator = None always = False textfile = None talkPage = True reorderEnabled = True namespaces = [] # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory() # Put the text above or below the text? up = False # Loading the arguments for arg in pywikibot.handleArgs(): if arg.startswith('-textfile'): if len(arg) == 9: textfile = pywikibot.input( u'Which textfile do you want to add?') else: textfile = arg[10:] elif arg.startswith('-text'): if len(arg) == 5: addText = pywikibot.input(u'What text do you want to add?') else: addText = 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('-page'): if len(arg) == 5: generator = [ pywikibot.Page( pywikibot.getSite(), pywikibot.input(u'What page do you want to use?')) ] else: generator = [pywikibot.Page(pywikibot.getSite(), arg[6:])] elif arg.startswith('-excepturl'): if len(arg) == 10: regexSkipUrl = pywikibot.input(u'What text should I skip?') else: regexSkipUrl = arg[11:] elif arg.startswith('-except'): if len(arg) == 7: regexSkip = pywikibot.input(u'What text should I skip?') else: regexSkip = arg[8:] elif arg.startswith('-untagged'): if len(arg) == 9: untaggedProject = pywikibot.input( u'What project do you want to use?') else: untaggedProject = arg[10:] generator = untaggedGenerator(untaggedProject) elif arg == '-up': up = True elif arg == '-noreorder': reorderEnabled = False elif arg == '-always': always = True # elif arg == '-talk' or arg == '-talkpage': # talkPage = True else: genFactory.handleArg(arg) if textfile and not addText: f = codecs.open(textfile, 'r', config.textfile_encoding) addText = f.read() f.close() if not generator: generator = genFactory.getCombinedGenerator() # Check if there are the minimal settings if not generator: raise NoEnoughData( 'You have to specify the generator you want to use for the script!' ) if talkPage: generator = pagegenerators.PageWithTalkPageGenerator(generator) site = pywikibot.getSite() for namespace in site.namespaces(): index = site.getNamespaceIndex(namespace) if index % 2 == 1 and index > 0: namespaces += [index] generator = pagegenerators.NamespaceFilterPageGenerator( generator, namespaces) # Main Loop for page in generator: # print "going to process %s" % page.title() print "going to process %s" % page.urlname() try: text = page.get() except: text = "" m = re.search("==archived on speedy deletion wikia==", text) if not (m): m = re.search("==archived==", text) if not (m): summary = "notification of speedy deletion page" newname = page.urlname() newname = newname.replace('Talk%3A', '') newtext = "==archived on speedy deletion wikia==\nThis endangered article has been archived here http://speedydeletion.wikia.com/wiki/%s so that it is not lost if deleted. Changes made after the archiving will not be copied.\n~~~~" % newname (text, newtext, always) = add_text(page, newtext, summary, regexSkip, regexSkipUrl, always, up, True, reorderEnabled=reorderEnabled, create=talkPage) else: print "skipping %s" % page.urlname() else: print "skipping %s" % page.urlname()
def main(): genFactory = pagegenerators.GeneratorFactory() args = [] # The generator gives the pages that should be worked upon. for x in range(2010, 2019): args.append('-cat:' + str(x) + " films") args.append('-cat:Upcoming films') for t in args: gen = None pageTitleParts = [] for arg in pywikibot.handleArgs(t): 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( pagegenerators.PageWithTalkPageGenerator(gen)) filmBot = Film.FilmBot(gen, False, False) bannerBot = Banner.FilmBannerBot(gen) imageBot = Images.FilmImageBot(gen, False, False) assessBot = Assess.FilmAssessBot(gen) infoboxBot = Infobox.InfoboxBot(gen, False, False, False) code = "ok" for page in gen: if (page.title().lower().find("user:"******"wikipedia talk:") == -1 and page.title().lower().find("category:") == -1): if not page.isTalkPage(): pageText = filmBot.load(page) title = page.title() filmBot.treat(page, pageText) code = imageBot.treat(pageText, page) else: talkText = filmBot.load(page) if bannerBot.check2(talkText, pageText): bannerBot.open(page) pywikibot.output(code) elif (pageText): #if bannerbot is not needed if code == "has" and re.search( "needs-image=yes", talkText): imageBot.doHasImage(title, page) #elif (not (re.search("\.jpg", pageText, re.I) or re.search("\.gif", pageText, re.I) or re.search("\.png", pageText, re.I) or re.search("\.jpeg", pageText, re.I) or re.search("\.tif", pageText, re.I))) and not re.search("needs-image=yes", talkText, re.I) and not re.search("class=list", talkText, re.I): # assessBot.treat(pageText, page.toggleTalkPage()) elif code == "found" and re.search( "needs-image=yes", talkText): imageBot.doNewImage(title, page) elif code == "noinfobox": infoboxBot.treat(page)