I have a subtitle file and I want to extract timestamps from the file. e.g. from below lines:
<SYNC Start=106377><P Class=ENCC>
Hey...
<SYNC Start=107350><P Class=ENCC>
close the door.
I want to extract timestamps '106377' and '107350' and append them with the name of the file including .bmp at the end. e.g. I want the line to look like
grey-anatomy_106377.bmp. I have written the below code but output only returns line with grey-anatomy_106377grey-anatomy_107350 and so on.
timings = []
file = open('grey-anatomy.smi', "r" )
wholefile = file.readlines()
for line in wholefile:
line = line.strip().lower()
if line.startswith("<sync"):
prefix, data = line.split("=",1)
timestamp, postfix = data.split(">",1)
try:
timings.append(timestamp)
except ValueError:
print "Ignoring this timestamp"
timings= 'grey-anatomy_'.join(timings).join('bmp')
fout = open("grey-anatomy1.txt", "w")
fout.writelines(timings)
fout.close()
I want each text output to include .bmp at end of every parsed entry and one entry should be on one single line like
grey-anatomy_106377.bmp
grey-anatomy_107350.bmp
[/QUOTE
How can I achieve this?