<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Task   : Migrate deprecated infobox coordinates parameters
Author : JJMC89


The following parameters are required:

-config           The page title that has the JSON config (object)
                    The config must contain:
                      - initialReplacementTemplate (string)
                      - parametersMap (object of string/array)
                      - replacementParameterNames (string/array)
                      - template (string)
                    The config may optionally contain:
                      - editSummary (string)


The following parameters are supported:

&params;
"""
from __future__ import absolute_import, unicode_literals

__version__ = '$Id$'

import json
import re
import statistics
import sys
from collections import OrderedDict
import mwparserfromhell
import pywikibot
from pywikibot import pagegenerators
from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot)

docuReplacements = {
    '&params;': pagegenerators.parameterHelp
}


def validate_config(config):
    """
    Validate the configuration and return bool
    @param config: configuration to validate
    @type config: dict
    """
    requiredKeys = [
      'initialReplacementTemplate',
      'parametersMap',
      'replacementParameterNames',
      'template'
    ]
    configKeys = []
    
    if not isinstance(config, dict):
        return False
    
    for key, value in config.items():
        if key == 'initialReplacementTemplate':
            if isinstance(value, str):
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        elif key == 'parametersMap':
            if not isinstance(value, dict):
                return False
            for k, v in value.items():
                if not isinstance(k, str):
                    return False
                if isinstance(v, str):
                    value[k] = [v]
                elif isinstance(v, list):
                    for i in v:
                        if not isinstance(i, str):
                            return False
                else:
                    return False
            if key in requiredKeys:
                configKeys.append(key)
        elif key == 'replacementParameterNames':
            if isinstance(value, str):
                value = [value]
            elif isinstance(value, list):
                for name in value:
                    if not isinstance(name, str):
                        return False
            else:
                return False
            if key in requiredKeys:
                configKeys.append(key)
        elif key == 'template':
            template = pywikibot.Page(pywikibot.Site(),
              u'Template:%s' % value)
            if not template.isRedirectPage():
                config[key] = template
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        elif key == 'editSummary':
            if value is None or isinstance(value, str):
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        else:
            return False
    
    if sorted(configKeys) != sorted(requiredKeys):
        return False
    
    return True


class InfoboxCoordinatesParametersMigrator(
  SingleSiteBot,
  ExistingPageBot,
  NoRedirectPageBot
):
    def __init__(self, generator, **kwargs):
        """
        Constructor.
        @param generator: the page generator that determines on which
            pages to work
        @type generator: generator
        """
        self.availableOptions.update({
          'editSummary': None,
          'initialReplacementTemplate': None,
          'parametersMap': None,
          'replacementParameterNames': None,
          'template': None
        })
        
        self.generator = generator
        super(InfoboxCoordinatesParametersMigrator, self).__init__(
          site=True, **kwargs)
          
        self.HTMLComment = re.compile(r'<!--.*?-->', flags=re.DOTALL)
        
        self.initialReplacementParameterValue = (
          mwparserfromhell.nodes.Template(
          self.getOption('initialReplacementTemplate').strip()))
        self.parametersMap = self.getOption('parametersMap')
        self.replacementParameterNames = self.getOption(
          'replacementParameterNames')
        self.template = self.getOption('template')
        self.templateTitles = [self.template.title(withNamespace=False)]
        for tpl in self.template.backlinks(
          filterRedirects=True,
          namespaces=self.site.namespaces.TEMPLATE
        ):
            self.templateTitles.append(tpl.title(withNamespace=False))
        summary = self.getOption('editSummary')
        if summary is None:
            self.summary = (
              u'Migrate {{%s}} coordinates parameters to {{Coord}}, '
              u'see [[Help:Coordinates in infoboxes]]' %
                self.template.title(withNamespace=False)
            )
        else:
            self.summary = summary.strip()
    
    def check_enabled(self):
        """Test if the task is enabled"""
        page = pywikibot.Page(self.site,
          u'User:%s/shutoff/%s' % (self.site.user(), self.__class__.__name__))
        if page.exists():
            content = page.get().strip()
            if content != u'':<commit_msg>Update default edit summary<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Task   : Migrate deprecated infobox coordinates parameters
Author : JJMC89


The following parameters are required:

-config           The page title that has the JSON config (object)
                    The config must contain:
                      - initialReplacementTemplate (string)
                      - parametersMap (object of string/array)
                      - replacementParameterNames (string/array)
                      - template (string)
                    The config may optionally contain:
                      - editSummary (string)


The following parameters are supported:

&params;
"""
from __future__ import absolute_import, unicode_literals

__version__ = '$Id$'

import json
import re
import statistics
import sys
from collections import OrderedDict
import mwparserfromhell
import pywikibot
from pywikibot import pagegenerators
from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot)

docuReplacements = {
    '&params;': pagegenerators.parameterHelp
}


def validate_config(config):
    """
    Validate the configuration and return bool
    @param config: configuration to validate
    @type config: dict
    """
    requiredKeys = [
      'initialReplacementTemplate',
      'parametersMap',
      'replacementParameterNames',
      'template'
    ]
    configKeys = []
    
    if not isinstance(config, dict):
        return False
    
    for key, value in config.items():
        if key == 'initialReplacementTemplate':
            if isinstance(value, str):
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        elif key == 'parametersMap':
            if not isinstance(value, dict):
                return False
            for k, v in value.items():
                if not isinstance(k, str):
                    return False
                if isinstance(v, str):
                    value[k] = [v]
                elif isinstance(v, list):
                    for i in v:
                        if not isinstance(i, str):
                            return False
                else:
                    return False
            if key in requiredKeys:
                configKeys.append(key)
        elif key == 'replacementParameterNames':
            if isinstance(value, str):
                value = [value]
            elif isinstance(value, list):
                for name in value:
                    if not isinstance(name, str):
                        return False
            else:
                return False
            if key in requiredKeys:
                configKeys.append(key)
        elif key == 'template':
            template = pywikibot.Page(pywikibot.Site(),
              u'Template:%s' % value)
            if not template.isRedirectPage():
                config[key] = template
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        elif key == 'editSummary':
            if value is None or isinstance(value, str):
                if key in requiredKeys:
                    configKeys.append(key)
            else:
                return False
        else:
            return False
    
    if sorted(configKeys) != sorted(requiredKeys):
        return False
    
    return True


class InfoboxCoordinatesParametersMigrator(
  SingleSiteBot,
  ExistingPageBot,
  NoRedirectPageBot
):
    def __init__(self, generator, **kwargs):
        """
        Constructor.
        @param generator: the page generator that determines on which
            pages to work
        @type generator: generator
        """
        self.availableOptions.update({
          'editSummary': None,
          'initialReplacementTemplate': None,
          'parametersMap': None,
          'replacementParameterNames': None,
          'template': None
        })
        
        self.generator = generator
        super(InfoboxCoordinatesParametersMigrator, self).__init__(
          site=True, **kwargs)
          
        self.HTMLComment = re.compile(r'<!--.*?-->', flags=re.DOTALL)
        
        self.initialReplacementParameterValue = (
          mwparserfromhell.nodes.Template(
          self.getOption('initialReplacementTemplate').strip()))
        self.parametersMap = self.getOption('parametersMap')
        self.replacementParameterNames = self.getOption(
          'replacementParameterNames')
        self.template = self.getOption('template')
        self.templateTitles = [self.template.title(withNamespace=False)]
        for tpl in self.template.backlinks(
          filterRedirects=True,
          namespaces=self.site.namespaces.TEMPLATE
        ):
            self.templateTitles.append(tpl.title(withNamespace=False))
        summary = self.getOption('editSummary')
        if summary is None:
            self.summary = (
              u'Migrate {{%s}} coordinates parameters to {{Coord}}, '
              u'see [[Wikipedia:Coordinates in infoboxes]]' %
                self.template.title(withNamespace=False)
            )
        else:
            self.summary = summary.strip()
    
    def check_enabled(self):
        """Test if the task is enabled"""
        page = pywikibot.Page(self.site,
          u'User:%s/shutoff/%s' % (self.site.user(), self.__class__.__name__))
        if page.exists():
            content = page.get().strip()
            if content != u'':
{'fraction_non_alphanumeric': 0.0864454290623022, 'fraction_numerical': 0.0007233927118184284, 'mean_word_length': 1.7362691736763978, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4419537', 'n_tokens_mistral': 2772, 'n_tokens_neox': 2670, 'n_words': 732}