<commit_before>#!/usr/bin/python3
# -*- coding: utf-8 -*-

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

class SmallSMILHandler(ContentHandler):

    def __init__ (self):
        """
        Constructor. Inicializamos las variables
        """
        self.width = ""
        self.height = ""
        self.background-color = ""
        self.id = ""
        self.top = ""
        self.bottom = ""
        self.left = "" 
        self.right = "" 
        self.src = ""
        self.region = ""  
        self.begin = ""
        self.dur = "" 
        self.list = [] 

    def startElement(self, name, attrs):
        """
        Método que se llama cuando se abre una etiqueta
        """
        if name == 'root-layout':
            # De esta manera tomamos los valores de los atributos
            self.width = attrs.get('width',"")
            self.height = attrs.get('heigth',"")
            self.background-color = attrs.get('background-color',"")
            self.list.append([name, attrs])

        elif name == 'region':
            self.id = attrs.get('width',"")
            self.top = attrs.get('heigth',"")
            self.bottom = attrs.get('background-color',"")
            self.left = attrs.get('left',"")
            self.right = attrs.get('rigth',"")
            self.list.append([name, attrs])

        if name == 'img':
            self.src = attrs.get('src',"")
            self.region = attrs.get('region',"")
            self.begin = attrs.get('begin',"")
            self.dur = attrs.get('dur',"")
            self.list.append([name, attrs])

        if name == 'audio':
            self.src = attrs.get('src',"")
            self.begin = attrs.get('begin',"")
            self.dur = attrs.get('dur',"")
            self.list.append([name, attrs])

        if name == 'textstream':
            self.src = attrs.get('src',"")
            self.region = attrs.get('region',"")
            self.list.append([name, attrs])

    def get_tags(self):
        """
        Metodo llamado get_tags que devolvera una lista con las etiquetas encontradas, 
        sus atributos y el contenido de los atributos. 
        """
        return self.list


if __name__ == "__main__":
    """
    Programa principal
    """
    parser = make_parser()
    cHandler = SmallSMILHandler()
    parser.setContentHandler(cHandler)
    parser.parse(open('karaoke.smil'))
    My_List = cHandler.get_tags()
    print(My_List)<commit_msg>Ejercicio 3 terminado - FALTA PASAR pep8<commit_after>#!/usr/bin/python3
# -*- coding: utf-8 -*-

from xml.sax import make_parser
from xml.sax.handler import ContentHandler

class SmallSMILHandler(ContentHandler):

    def __init__ (self):

        self.dicc = {'root-layout': ['width', 'height', 'background-color'],
                    'region': ['id', 'top', 'bottom', 'left', 'right'],
                    'img': ['src', 'region', 'begin', 'dur'],
                    'audio': ['src', 'begin', 'dur'],
                    'textstream': ['src', 'region']}

        self.list = [] 

    def startElement(self, name, attrs):
        """
        Método que se llama cuando se abre una etiqueta
        """
        if name in self.dicc:
            newdicc = {}
            for atribute in self.dicc[name]:
                newdicc[atribute] = attrs.get(atribute, "")
            self.list.append([name, newdicc])

    def get_tags(self):

        return self.list

if __name__ == "__main__":
    """
    Programa principal
    """
    parser = make_parser()
    cHandler = SmallSMILHandler()
    parser.setContentHandler(cHandler)
    parser.parse(open('karaoke.smil'))
    My_List = cHandler.get_tags()
    print(My_List)
{'fraction_non_alphanumeric': 0.15317762085822922, 'fraction_numerical': 0.0016295491580662683, 'mean_word_length': 1.9487590072057646, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3784466', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1146, 'n_words': 239}