<commit_before>#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from smallsmilhandler import SmallSMILHandler
import json


def take_filename():
    if len(sys.argv) != 2:
        sys.exit("Usage:  python3 karaoke.py file.smil")
    else:
        return sys.argv[1]
def show_smil(list_labels):
    for label in list_labels:
        label_name = label[0]
        attributes = label[1]
        sys.stdout.write(label_name + '\\')
        for key, value in attributes.items():
            if value != '':
                # sys.stdout.write('%s="%s"\\' % (key, value))
                sys.stdout.write(key + '=' + '"'+ value + '"' + '\\')
        print('n')

def do_json_file(list_labels):

    data = json.dumps(list_labels)
    with open('labels.json', 'w') as outfile:
        json.dump(data, outfile)

if __name__ == "__main__":
    filename = take_filename()
    parser = make_parser()
    cHandler = SmallSMILHandler()
    parser.setContentHandler(cHandler)
    parser.parse(open(filename))
    list_labels = cHandler.get_tags()
    show_smil(list_labels)
    do_json_file(list_labels)
<commit_msg>Ejercicio 5 hecho<commit_after>#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
from smallsmilhandler import SmallSMILHandler
import json
import urllib.request



def take_filename():
    if len(sys.argv) != 2:
        sys.exit("Usage:  python3 karaoke.py file.smil")
    else:
        return sys.argv[1]
def show_smil(list_labels):
    for label in list_labels:
        label_name = label[0]
        attributes = label[1]
        sys.stdout.write(label_name + '\\')
        for key, value in attributes.items():
            if value != '':
                # sys.stdout.write('%s="%s"\\' % (key, value))
                sys.stdout.write(key + '=' + '"'+ value + '"' + '\\')
        print('n')

def do_json_file(list_labels):

    data = json.dumps(list_labels)
    with open('labels.json', 'w') as outfile:
        json.dump(data, outfile)

def get_url(list_labels):
    for label in list_labels:
        attributes = label[1]
        for key in attributes:
            if 'http://' in attributes[key]:
                filename = attributes[key].split('/')[-1]
                urllib.request.urlretrieve(attributes[key], filename)
                attributes[key] = filename

if __name__ == "__main__":
    filename = take_filename()
    parser = make_parser()
    cHandler = SmallSMILHandler()
    parser.setContentHandler(cHandler)
    parser.parse(open(filename))
    list_labels = cHandler.get_tags()
    do_json_file(list_labels)
    get_url(list_labels)
    show_smil(list_labels)

{'fraction_non_alphanumeric': 0.13437727603787328, 'fraction_numerical': 0.006190823015294974, 'mean_word_length': 2.707152496626181, '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': '41751', 'n_tokens_mistral': 901, 'n_tokens_neox': 887, 'n_words': 189}