<commit_before>#coding=utf-8
import zipfile
import os.path
import datetime


class aemet_rename(object):
    u"""
    Renombra según reglas heredadas del Movedor de Jaime

        >>> processor = add_date_prefix('%Y_%m_')
        >>> processor.now = lambda: datetime.datetime(2007,3,1)
        >>> processor._new_name('foo')
        '2007_03_foo'
    """
    now = datetime.datetime.utcnow # To mock in tests
    def __call__(self, path):
        basename = os.path.basename(path)
        errors = []
        if os.path.getsize(path) == 0:
            errors.append('VACIO')
        if path.lower().endswith('.zip'):
            try:
                zf = zipfile.ZipFile(path, 'r')
                if zf.testzip():
                    errors.append('ZIP_ERRONEO')
            except zipfile.BadZipfile:   
                    errors.append('NO_ES_ZIP')
        if basename.startswith('10'):
            new_name = 'Algunos-SYNOPs-' + basename[4:6] + self.now().strftime('-%Y-%m-%d-') \
                    + basename[6:8] + '00.txt'
        elif basename.startswith('SYNOP'):
            new_name = 'S' + basename[5:6] + self.now().strftime('-%Y-%m-%d-') \
                + basename[6:8] + '00.txt'
        elif basename.startswith('W'):
            new_name = basename[0:8] + self.now().strftime('_%Y-%m-%d_%H-%M-%S') \
                + '.txt'
        elif basename.startswith('SYHOAU'):
            new_name = 'SHA' + self.now().strftime('-%Y-%m-%d-') \
                + basename[6:8] + '00.txt'
        else:
            new_name = basename
        if errors:
            new_name += '.' + '.'.join(errors)
        with open(path) as f:
            yield new_name, f.read()
<commit_msg>Cambia aemet_rename a función porque config entiende que es una función<commit_after>#coding=utf-8
import zipfile
import os.path
import datetime


def aemet_rename(path):
    u"""
    Renombra según reglas heredadas del Movedor de Jaime

        >>> processor = add_date_prefix('%Y_%m_')
        >>> processor.now = lambda: datetime.datetime(2007,3,1)
        >>> processor._new_name('foo')
        '2007_03_foo'
    """
    basename = os.path.basename(path)
    errors = []
    if os.path.getsize(path) == 0:
        errors.append('VACIO')
    if path.lower().endswith('.zip'):
        try:
            zf = zipfile.ZipFile(path, 'r')
            if zf.testzip():
                errors.append('ZIP_ERRONEO')
        except zipfile.BadZipfile:   
                errors.append('NO_ES_ZIP')
    if basename.startswith('10'):
        new_name = 'Algunos-SYNOPs-' + basename[4:6] + aemet_rename.now().strftime('-%Y-%m-%d-') \
                + basename[6:8] + '00.txt'
    elif basename.startswith('SYNOP'):
        new_name = 'S' + basename[5:6] + aemet_rename.now().strftime('-%Y-%m-%d-') \
            + basename[6:8] + '00.txt'
    elif basename.startswith('W'):
        new_name = basename[0:8] + aemet_rename.now().strftime('_%Y-%m-%d_%H-%M-%S') \
            + '.txt'
    elif basename.startswith('SYHOAU'):
        new_name = 'SHA' + aemet_rename.now().strftime('-%Y-%m-%d-') \
            + basename[6:8] + '00.txt'
    else:
        new_name = basename
    if errors:
        new_name += '.' + '.'.join(errors)
    with open(path) as f:
        yield new_name, f.read()

aemet_rename.now = datetime.datetime.utcnow # To mock in tests

{'fraction_non_alphanumeric': 0.16526694661067787, 'fraction_numerical': 0.020395920815836834, 'mean_word_length': 2.0596330275229358, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5352836', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1172, 'n_words': 199}