- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
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
Нус, зацените мой первый опыт с питоном. Говнецо редкое, жаль просто так смывать. Так что пусть полежит здесь.