Reflect stucture changes in Code
Since bot class is moved to separate dir/file we need to do some changes to rebuild functionality Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=82 FS#82]
This commit is contained in:
2
bots/__init__.py
Normal file
2
bots/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
@@ -22,15 +22,13 @@
|
||||
#
|
||||
#
|
||||
"""
|
||||
Script to parse all reddisc pages in configured categories
|
||||
Bot to parse all reddisc pages in given Generator or configured categories
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
|
||||
import pywikibot
|
||||
from pywikibot import pagegenerators
|
||||
import pywikibot # noqa
|
||||
from pywikibot import pagegenerators # noqa
|
||||
from pywikibot.bot import ExistingPageBot, NoRedirectPageBot
|
||||
|
||||
import jogobot
|
||||
@@ -127,104 +125,3 @@ class DiscussionParserBot(
|
||||
reddisc=red_page.page.title() ) +
|
||||
"containing no redfam, parsed!",
|
||||
"WARNING" )
|
||||
|
||||
|
||||
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.
|
||||
|
||||
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")]
|
||||
|
||||
# Before run, we need to check wether we are currently active or not
|
||||
try:
|
||||
# Will throw Exception if disabled/blocked
|
||||
# jogobot.is_active( task_slug )
|
||||
pass
|
||||
|
||||
except jogobot.jogobot.Blocked:
|
||||
(type, value, traceback) = sys.exc_info()
|
||||
jogobot.output( "\03{lightpurple} %s (%s)" % (value, type ),
|
||||
"CRITICAL" )
|
||||
|
||||
except jogobot.jogobot.Disabled:
|
||||
(type, value, traceback) = sys.exc_info()
|
||||
jogobot.output( "\03{red} %s (%s)" % (value, type ),
|
||||
"ERROR" )
|
||||
|
||||
# Bot/Task is active
|
||||
else:
|
||||
|
||||
# This factory is responsible for processing command line arguments
|
||||
# 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
|
||||
|
||||
# If force_reload is True, bot will always parse Countrylist regardless
|
||||
# if parsing is needed or not
|
||||
# force_reload = False
|
||||
|
||||
# Parse command line arguments
|
||||
for arg in local_args:
|
||||
if arg.startswith("-always"):
|
||||
# always = True
|
||||
pass
|
||||
else:
|
||||
genFactory.handleArg(arg)
|
||||
|
||||
if not gen:
|
||||
|
||||
# Check wether there are generators waiting for factoring, if not
|
||||
# use configured categories
|
||||
if not genFactory.gens:
|
||||
apply_conf_cat_generators( genFactory )
|
||||
|
||||
# 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()
|
||||
|
||||
if( __name__ == "__main__" ):
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user