From 17bfb32dede157bf33272c1a025b357729850561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Wed, 24 Aug 2016 11:13:12 +0200 Subject: [PATCH] Building generators of config cats in sep Function Since the main()-Function was too complex the logic to build generators out of categories provided in jogobot.conf was moved in a separate function [https://fs.golderweb.de/index.php?do=details&task_id=73 FS#73] Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=72 FS#72] Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=72 FS#72] --- reddiscparser.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/reddiscparser.py b/reddiscparser.py index 2d7164f..cd9cf29 100644 --- a/reddiscparser.py +++ b/reddiscparser.py @@ -106,7 +106,26 @@ class DiscussionParserBot( reddisc=red_page.page.title() ) ) -def main(*args): # noqa +def apply_conf_cat_generators( genFactory ): + """ + 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"]: + cgen = genFactory.getCategoryGen( + category, gen_func=pagegenerators.CategorizedPageGenerator) + + # If there is one, append to genFactory + if cgen: + genFactory.gens.append(cgen) + + +def main(*args): """ Process command line arguments and invoke bot. @@ -168,16 +187,7 @@ def main(*args): # noqa # Check wether there are generators waiting for factoring, if not # use configured categories if not genFactory.gens: - - # Create Generators for configured Categories - for category in jogobot.config["redundances"]["redpage_cats"]: - cgen = genFactory.getCategoryGen( - category, - gen_func=pagegenerators.CategorizedPageGenerator) - - # If there is one, append to genFactory - if cgen: - genFactory.gens.append(cgen) + apply_conf_cat_generators( genFactory ) # Create combined Generator (Union of all Generators) gen = genFactory.getCombinedGenerator()