diff --git a/red.py b/red.py index bee76b8..dd14625 100644 --- a/red.py +++ b/red.py @@ -32,26 +32,6 @@ import pywikibot from pywikibot import pagegenerators import jogobot -from bots.reddiscparser import DiscussionParserBot - - -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): @@ -68,7 +48,7 @@ def main(*args): local_args = pywikibot.handle_args(args) # Get the jogobot-task_slug (basename of current file without ending) - task_slug = os.path.basename(__file__)[:-len(".py")] + task_slug = os.path.basename(__file__)[:-len(".py")] # noqa (temp) # Before run, we need to check wether we are currently active or not try: @@ -93,8 +73,6 @@ def main(*args): # that are also used by other scripts and that determine on which pages # to work on. genFactory = pagegenerators.GeneratorFactory() - # The generator gives the pages that should be worked upon. - gen = None # If always is True, bot won't ask for confirmation of edit (automode) # always = False @@ -103,34 +81,41 @@ def main(*args): # if parsing is needed or not # force_reload = False + # Subtask selects the specific bot to run + # Default is reddiscparser + subtask = None + + # kwargs are passed to selected bot as **kwargs + kwargs = dict() # noqa (temp) + # Parse command line arguments for arg in local_args: + + # Split args + arg, sep, value = arg.partition(':') + if arg.startswith("-always"): # always = True pass + elif arg.startswith("-task"): + subtask = value else: genFactory.handleArg(arg) - if not gen: + # After parsing args we can select bot to run + if not subtask or subtask == "discparser": + # Default case: discparser + subtask = "discparser" - # Check wether there are generators waiting for factoring, if not - # use configured categories - if not genFactory.gens: - apply_conf_cat_generators( genFactory ) + # Import related bot + from bots.reddiscparser import DiscussionParserBot as Bot # noqa (temp) - # Create combined Generator (Union of all Generators) - gen = genFactory.getCombinedGenerator() - - if gen: - # Log beginning of parsing - jogobot.output( "{task_slug} invoked".format(task_slug=task_slug) ) - - # The preloading generator is responsible for downloading multiple - # pages from the wiki simultaneously. - gen = pagegenerators.PreloadingGenerator(gen) - DiscussionParserBot( gen ).run() + # else: - pywikibot.showHelp() + jogobot.output( ( + "\03{{red}} Given subtask \"{subtask} \"" + + "is not existing!" ).format( subtask=subtask ), "ERROR" ) + if( __name__ == "__main__" ): main()