The basic framework for bot
This commit is contained in:
+117
@@ -0,0 +1,117 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# teamstation.py
|
||||||
|
#
|
||||||
|
# Copyright 2018 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.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
"""
|
||||||
|
Bot to correct errors in usage of
|
||||||
|
[Template Team-Station](https://de.wikipedia.org/wiki/Vorlage:Team-Station).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import locale
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pywikibot
|
||||||
|
from pywikibot.bot import CurrentPageBot
|
||||||
|
|
||||||
|
import jogobot
|
||||||
|
|
||||||
|
|
||||||
|
class TeamstationBot( CurrentPageBot ): # sets 'current_page' on each treat()
|
||||||
|
"""
|
||||||
|
Bot to correct errors in usage of [Template Team-Station]
|
||||||
|
(https://de.wikipedia.org/wiki/Vorlage:Team-Station).
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__( self, genFactory, **kwargs ):
|
||||||
|
"""
|
||||||
|
Constructor
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
@param genFactory GenFactory with parsed pagegenerator args to
|
||||||
|
build generator
|
||||||
|
@type genFactory pagegenerators.GeneratorFactory
|
||||||
|
@param **kwargs Additional args
|
||||||
|
@type iterable
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Copy needed args
|
||||||
|
self.genFactory = genFactory
|
||||||
|
|
||||||
|
# Build generator with genFactory
|
||||||
|
self.build_generator()
|
||||||
|
|
||||||
|
# Run super class init with builded generator
|
||||||
|
super( TeamstationBot, self ).__init__(generator=self.gen)
|
||||||
|
|
||||||
|
def build_generator( self ):
|
||||||
|
"""
|
||||||
|
Builds generator
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Use this to create the generator the bot should work on
|
||||||
|
self.gen = self.genFactory.getCombinedGenerator()
|
||||||
|
|
||||||
|
def treat_page( self ):
|
||||||
|
"""
|
||||||
|
Handles work on current page
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Make sure locale is set to 'de_DE.UTF-8' to prevent problems
|
||||||
|
# with wrong month abreviations in strptime
|
||||||
|
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||||
|
|
||||||
|
# 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")]
|
||||||
|
|
||||||
|
# Actually not needed since we only run semi-automaticall
|
||||||
|
# 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, None )
|
||||||
|
|
||||||
|
# Init Bot
|
||||||
|
bot = jogobot.bot.init_bot( task_slug, None, TeamstationBot, genFactory)
|
||||||
|
|
||||||
|
# Run bot
|
||||||
|
jogobot.bot.run_bot( task_slug, None, bot )
|
||||||
|
|
||||||
|
|
||||||
|
if( __name__ == "__main__" ):
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user