Jonathan Golder
8 years ago
4 changed files with 180 additions and 112 deletions
@ -0,0 +1,2 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
# -*- coding: utf-8 -*- |
@ -1 +1 @@ |
|||||
Subproject commit 2173f2984f1de6950728a15709bf93db5188731d |
Subproject commit 28d03f35b848a33ad45d3f5f8f3f82e8c45534ec |
@ -0,0 +1,118 @@ |
|||||
|
#!/usr/bin/env python3 |
||||
|
# -*- coding: utf-8 -*- |
||||
|
# |
||||
|
# reddiscparser.py |
||||
|
# |
||||
|
# Copyright 2016 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de> |
||||
|
# |
||||
|
# This program is free software; you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation; either version 2 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program; if not, write to the Free Software |
||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
||||
|
# MA 02110-1301, USA. |
||||
|
# |
||||
|
# |
||||
|
""" |
||||
|
Wrapper script to invoke all redundances bot tasks |
||||
|
""" |
||||
|
|
||||
|
import os |
||||
|
|
||||
|
import pywikibot |
||||
|
|
||||
|
import jogobot |
||||
|
|
||||
|
|
||||
|
def prepare_bot( task_slug, subtask, genFactory, subtask_args ): |
||||
|
""" |
||||
|
Handles importing subtask Bot class and prepares specific args |
||||
|
|
||||
|
Throws exception if bot not exists |
||||
|
|
||||
|
@param task_slug Task slug, needed for logging |
||||
|
@type task_slug str |
||||
|
@param subtask Slug of given subtask |
||||
|
@type subtask str |
||||
|
@param genFactory GenFactory with parsed pagegenerator args |
||||
|
@type genFactory pagegenerators.GeneratorFactory |
||||
|
@param subtask_args Additional args for subtasks |
||||
|
@type subtask_args dict\ |
||||
|
|
||||
|
@returns The following tuple |
||||
|
@return 1 Subtask slug (replaced None for default) |
||||
|
@rtype str |
||||
|
@return 2 Botclass of given subtask (Arg "-task") |
||||
|
@rtype Class |
||||
|
@return 3 GenFactory with parsed pagegenerator args |
||||
|
@rtype pagegenerators.GeneratorFactory |
||||
|
@return 4 Additional args for subtasks |
||||
|
@rtype dict |
||||
|
@rtype tuple |
||||
|
""" |
||||
|
# kwargs are passed to selected bot as **kwargs |
||||
|
kwargs = dict() |
||||
|
|
||||
|
if not subtask or subtask == "discparser": |
||||
|
# Default case: discparser |
||||
|
subtask = "discparser" |
||||
|
|
||||
|
# Import related bot |
||||
|
from bots.reddiscparser import DiscussionParserBot as Bot |
||||
|
|
||||
|
# Subtask error |
||||
|
else: |
||||
|
jogobot.output( ( |
||||
|
"\03{{red}} Given subtask \"{subtask} \"" + |
||||
|
"is not existing!" ).format( subtask=subtask ), "ERROR" ) |
||||
|
raise Exception |
||||
|
|
||||
|
return ( subtask, Bot, genFactory, kwargs ) |
||||
|
|
||||
|
|
||||
|
def main(*args): |
||||
|
""" |
||||
|
Process command line arguments and invoke bot. |
||||
|
|
||||
|
If args is an empty list, sys.argv is used. |
||||
|
|
||||
|
@param args: command line arguments |
||||
|
@type args: list of unicode |
||||
|
""" |
||||
|
|
||||
|
# Process global arguments to determine desired site |
||||
|
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")] |
||||
|
|
||||
|
# Disabled until [FS#86] is done |
||||
|
# Before run, we need to check wether we are currently active or not |
||||
|
# if not jogobot.bot.active( task_slug ): |
||||
|
# return |
||||
|
|
||||
|
# Parse local Args to get information about subtask |
||||
|
( subtask, genFactory, subtask_args ) = jogobot.bot.parse_local_args( |
||||
|
local_args ) |
||||
|
|
||||
|
# select subtask and prepare args |
||||
|
( subtask, Bot, genFactory, kwargs ) = prepare_bot( |
||||
|
task_slug, subtask, genFactory, subtask_args ) |
||||
|
|
||||
|
# Init Bot |
||||
|
bot = jogobot.bot.init_bot( task_slug, subtask, Bot, genFactory, **kwargs) |
||||
|
|
||||
|
# Run bot |
||||
|
jogobot.bot.run_bot( task_slug, subtask, bot ) |
||||
|
|
||||
|
|
||||
|
if( __name__ == "__main__" ): |
||||
|
main() |
Loading…
Reference in new issue