From 82390a4df5d692addc628e591a5266f57354f7cd Mon Sep 17 00:00:00 2001 From: Jonathan Golder Date: Sat, 8 Sep 2018 12:23:14 +0200 Subject: [PATCH] The basic framework for bot --- teamstation.py | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 teamstation.py diff --git a/teamstation.py b/teamstation.py new file mode 100644 index 0000000..9c078e7 --- /dev/null +++ b/teamstation.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# teamstation.py +# +# Copyright 2018 Jonathan Golder +# +# 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()