<commit_before>import sys
from lxml import etree

filename = sys.argv[1]
srt_file = filename +'.srt'

xmlo = etree.parse(filename)
count = int(xmlo.xpath('count(//Subtitle)'))
counter = 0

with open(srt_file, "w") as myfile:
       print 'Transforming ', count, 'subtitles'

while counter < count:
    counter2 = counter +1
    in_point = xmlo.xpath('//Subtitle')[counter].attrib['TimeIn']
    out = xmlo.xpath('//Subtitle')[counter].attrib['TimeOut']
    in_point = in_point[:8] + '.' + in_point[9:]
    out = out[:8] + '.' + out[9:]

    with open(srt_file, "a") as myfile:
        myfile.write(str(counter + 1) + '\n')
        myfile.write(in_point + ' --> ' + out + '\n')
        bla =  [bla.text for bla in xmlo.iterfind('.//Subtitle[%s]/Text' % int(counter2) ) ]
        for i in bla:
                myfile.write(i + '\n')
        myfile.write('\n')

        print 'Transforming ' + str(counter) + ' of' + str(count) + ' subtitles\r' ,
          
    counter +=1 <commit_msg>dcpsubs2srt.py - cleanup and better variables<commit_after>import sys
from lxml import etree

filename = sys.argv[1]
srt_file = filename +'.srt'

dcp_subtitle = etree.parse(filename)
total_subtitles = int(dcp_subtitle.xpath('count(//Subtitle)'))
counter = 0

with open(srt_file, "w") as myfile:
       print  srt_file,' created'

while counter < total_subtitles:
    xpath_counter = counter + 1
    in_point      = dcp_subtitle.xpath('//Subtitle')[counter].attrib['TimeIn']
    out_point     = dcp_subtitle.xpath('//Subtitle')[counter].attrib['TimeOut']
    in_point      = in_point[:8]  + '.' + in_point[9:]
    out_point     = out_point[:8] + '.' + out_point[9:]

    with open(srt_file, "a") as myfile:
        myfile.write(str(counter + 1) + '\n')
        myfile.write(in_point + ' --> ' + out_point + '\n')
        subtitle_text =  [subtitle_text.text for subtitle_text in dcp_subtitle.iterfind('.//Subtitle[%s]/Text' % int(xpath_counter) ) ]
        for i in subtitle_text:
                myfile.write(i + '\n')
        myfile.write('\n')
        
    counter +=1 
{'fraction_non_alphanumeric': 0.16707257671699952, 'fraction_numerical': 0.010228933268387726, 'mean_word_length': 2.8827977315689983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '5165880', 'n_tokens_mistral': 777, 'n_tokens_neox': 756, 'n_words': 147}