diff --git a/bots/reddiscparser.py b/bots/reddiscparser.py index 7f66a2f..2a47642 100644 --- a/bots/reddiscparser.py +++ b/bots/reddiscparser.py @@ -58,7 +58,47 @@ class DiscussionParserBot( to work. @type generator: generator. """ - super( DiscussionParserBot, self ).__init__(generator=generator) + + def build_generator(self): + """ + Builds generator to work on, based on self.genFactory + """ + # Check wether there are generators waiting for factoring, if not + # use configured categories + if not self.genFactory.gens: + self.apply_conf_cat_generators() + + # Create combined Generator (Union of all Generators) + gen = self.genFactory.getCombinedGenerator() + + if gen: + # The preloading generator is responsible for downloading multiple + # pages from the wiki simultaneously. + self.gen = pagegenerators.PreloadingGenerator(gen) + + else: + pywikibot.showHelp() + + def apply_conf_cat_generators( self ): + """ + Builds generators for categories which are read from jogobot.config + + Parameters: + @param genFactory: The GeneratorFactory to which the builded + generators should be added. + @type genFactory: pagegenerators.GeneratorFactory + """ + # Create Generators for configured Categories + for category in jogobot.config["redundances"]["redpage_cats"]: + gen = self.genFactory.getCategoryGen( + category, gen_func=pagegenerators.CategorizedPageGenerator) + + # If there is one, append to genFactory + if gen: + self.genFactory.gens.append(gen) + + # Reset gen for next iteration + gen = None def run( self ): """