From d9d385cfe8ccd27d9ff61ce776518fa96f2c97fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Tue, 23 Feb 2016 11:40:15 +0100 Subject: [PATCH 1/4] Rename chartsbot.py to charts.py to get filename same as task_slug for jogobot-module --- chartsbot.py => charts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename chartsbot.py => charts.py (99%) diff --git a/chartsbot.py b/charts.py similarity index 99% rename from chartsbot.py rename to charts.py index e3b5562..bd5fabf 100644 --- a/chartsbot.py +++ b/charts.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# chartsbot.py +# charts.py # # original version by: # From d76f91461513c5f64cce46e55f95030c8852a7fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Tue, 23 Feb 2016 13:57:56 +0100 Subject: [PATCH 2/4] Use JogoBot StatusAPI to check if Bot/Task is active --- .gitignore | 2 ++ charts.py | 98 +++++++++++++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index a68441e..2ae00d0 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,5 @@ target/ # Test test.py + +disabled diff --git a/charts.py b/charts.py index bd5fabf..a26d50d 100644 --- a/charts.py +++ b/charts.py @@ -11,7 +11,7 @@ # # modified by: # -# Copyright 2015 GOLDERWEB – Jonathan Golder +# Copyright 2016 GOLDERWEB – 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 @@ -46,6 +46,8 @@ The following parameters are supported: import locale +import os +import sys import pywikibot from pywikibot import pagegenerators @@ -199,43 +201,65 @@ def main(*args): @param args: command line arguments @type args: list of unicode """ - # Process global arguments to determine desired site - local_args = pywikibot.handle_args(args) - - # 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 of - # parsing is needed or not - force_reload = False - - # Parse command line arguments - for arg in local_args: - if arg.startswith("-always"): - always = True - elif arg.startswith("-force-reload"): - force_reload = True - else: - genFactory.handleArg(arg) - - if not gen: - gen = genFactory.getCombinedGenerator() - if gen: - # The preloading generator is responsible for downloading multiple - # pages from the wiki simultaneously. - gen = pagegenerators.PreloadingGenerator(gen) - bot = ChartsBot(gen, always, force_reload) - if bot: - bot.run() + + # 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 ) + + 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: - pywikibot.showHelp() + # Process global arguments to determine desired site + local_args = pywikibot.handle_args(args) + + # 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 + elif arg.startswith("-force-reload"): + force_reload = True + else: + pass + genFactory.handleArg(arg) + + if not gen: + gen = genFactory.getCombinedGenerator() + if gen: + # The preloading generator is responsible for downloading multiple + # pages from the wiki simultaneously. + gen = pagegenerators.PreloadingGenerator(gen) + bot = ChartsBot(gen, always, force_reload) + if bot: + bot.run() + else: + pywikibot.showHelp() if( __name__ == "__main__" ): main() From 7b275779154efcd13971b31c940762569bb60d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Tue, 23 Feb 2016 13:58:46 +0100 Subject: [PATCH 3/4] Remove provisonal onwiki activation --- charts.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/charts.py b/charts.py index a26d50d..f1befb0 100644 --- a/charts.py +++ b/charts.py @@ -101,14 +101,6 @@ class ChartsBot( ): # Set locale to 'de_DE.UTF-8' locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8') - # provisional-onwiki-activation - page_active = pywikibot.Page( self.site, "Benutzer:JogoBot/active" ) - text_active = page_active.get() - - if "true" not in text_active.lower(): - pywikibot.output( "Bot ist deaktiviert!" ) - return False - def run(self): """Process each page from the generator.""" for page in self.generator: From df2f13fb66b55dad82f21a33ad11d849c73f497b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?GOLDERWEB=20=E2=80=93=20Jonathan=20Golder?= Date: Thu, 25 Feb 2016 16:26:10 +0100 Subject: [PATCH 4/4] Update jogobot --- jogobot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jogobot b/jogobot index 0daf72b..b0c844b 160000 --- a/jogobot +++ b/jogobot @@ -1 +1 @@ -Subproject commit 0daf72b625bc84a6029f74b37978e57e42237c82 +Subproject commit b0c844b2de2503eb77a172e57a288f947a978530