# Path: bormeparser/config.py
# CONFIG = dict(config["general"])


import os
import re
import datetime
import unicodedata
from .config import CONFIG
BORME_WEB_URL = "{protocol}://www.boe.es/borme/dias/{year}/{month:02d}/{day:02d}/index.php?s={seccion}"


def get_borme_website(date, seccion, secure=True):
    protocol = 'https' if secure else 'http'
    return BORME_WEB_URL.format(protocol=protocol, year=date.year, month=date.month, day=date.day, seccion=seccion)


def remove_accents(string):
    try:
        return ''.join((c for c in unicodedata.normalize('NFKD', string) if unicodedata.category(c) != 'Mn'))
    except TypeError:
        return ''.join((c for c in unicodedata.normalize('NFKD', unicode(string, 'utf-8')) if unicodedata.category(c) != 'Mn'))


def acto_to_attr(acto):
    attr = remove_accents(acto).replace(' del ', ' ').replace(' por ', ' ').replace(' de ', ' ')
    attr = attr.replace(' ', '_').replace('/', '_').replace('.', '_').lower()
    attr = re.sub('[^A-Za-z_]+', '', attr)
    return attr.rstrip('_')


def get_borme_xml_filepath(date, directory=CONFIG["borme_root"]):
    year = str(date.year)
    month = '{:02d}'.format(date.month)
    day = '{:02d}'.format(date.day)
    filename = 'BORME-S-{}{}{}.xml'.format(year, month, day)
    return os.path.join(directory, 'xml', year, month, filename)



# Path: bormeparser/config.py
# CONFIG = dict(config["general"])


# Path: bormeparser/utils.py
import os
import re
import datetime
import unicodedata
from .config import CONFIG

BORME_WEB_URL = "{protocol}://www.boe.es/borme/dias/{year}/{month:02d}/{day:02d}/index.php?s={seccion}"


def get_borme_website(date, seccion, secure=True):
    protocol = 'https' if secure else 'http'
    return BORME_WEB_URL.format(protocol=protocol, year=date.year, month=date.month, day=date.day, seccion=seccion)


def remove_accents(string):
    try:
        return ''.join((c for c in unicodedata.normalize('NFKD', string) if unicodedata.category(c) != 'Mn'))
    except TypeError:
        return ''.join((c for c in unicodedata.normalize('NFKD', unicode(string, 'utf-8')) if unicodedata.category(c) != 'Mn'))


def acto_to_attr(acto):
    attr = remove_accents(acto).replace(' del ', ' ').replace(' por ', ' ').replace(' de ', ' ')
    attr = attr.replace(' ', '_').replace('/', '_').replace('.', '_').lower()
    attr = re.sub('[^A-Za-z_]+', '', attr)
    return attr.rstrip('_')


def get_borme_xml_filepath(date, directory=CONFIG["borme_root"]):
    year = str(date.year)
    month = '{:02d}'.format(date.month)
    day = '{:02d}'.format(date.day)
    filename = 'BORME-S-{}{}{}.xml'.format(year, month, day)
    return os.path.join(directory, 'xml', year, month, filename)



def get_borme_pdf_path(date, directory=CONFIG["borme_root"]):