Mistři v programování na #hovnokod

Python #395

import xml.parsers.expat

text = 'lol'
booltext = 'false'

subs_temp = open('subs_temp.txt','w')

def start_element(name, attrs):
	if (name == 'rectRegion' and attrs['h']=='7.222' and attrs['y']=='92.778'):
		subs_temp.write(attrs['t'] + '\n')
		global text
		subs_temp.write(text + '\n')
	elif (name == 'TEXT'):
		global booltext
		booltext = 'true'
		
	#subs.write(name+'\n')
	#print(attrs)

def char_data(data):
	global text
	global booltext
	if (booltext == 'true'):
		text = data
		booltext = 'false'

p = xml.parsers.expat.ParserCreate("UTF-8")

p.StartElementHandler = start_element
p.CharacterDataHandler = char_data

p.ParseFile(open("yt.xml", 'rb'))

subs_temp.close()

subs_temp = open('subs_temp.txt','r')
subs = open('subs.txt','w')

num = 1

while num <= 44:
	time1 = subs_temp.readline()
	text = subs_temp.readline()
	time2 = subs_temp.readline()
	text = subs_temp.readline()

	subs.write(str(num))
	subs.write('\n0')
	subs.write(time1[:-1])
	subs.write('00 --> ')
	subs.write(time2[:-1])
	subs.write('00\n')
	subs.write(text)
	subs.write('\n')
	
	num+=1

HovnoKod,