-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclean.py
More file actions
64 lines (50 loc) · 1.12 KB
/
clean.py
File metadata and controls
64 lines (50 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
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
57
58
59
60
61
62
63
64
import string
class preprocessing:
def __init__(self):
self.x = 1;
def voiceover(self,inpf):
with open(inpf) as fin:
line = fin.readlines()
print(line)
def del_words(self,inpf,outf):
delete_list = ["CUT TO\n", " (V.O.)","FADE TO BLACK:\n"]
f = open(inpf,"r+")
d = f.readlines()
f.seek(0)
for i in d:
if i!="\n":
f.write(i)
f.truncate()
f.close()
fin = open(inpf,"r+")
fout = open("intermediate.txt", "w+")
for line in fin:
for word in delete_list:
line = line.replace(word, "")
fout.write(line)
fin.close()
fout.close()
fin = open("intermediate.txt","r")
fout = open(outf,"w")
fin.seek(0)
fout.seek(0)
d = fin.readlines()
x =[]
toggle = 0
for i in d:
if i.isupper() == False:
i = i.replace("\n","")
x.append(i)
else:
temp = ' '.join(x)
fout.write(temp)
fout.write("\n")
i = i.replace("\n","")
fout.write(i)
fout.write(": ")
x = []
inpf = 'fightclub_dialog.txt'
outf = 'output.txt'
clean = preprocessing()
clean.voiceover(outf)
clean.del_words(inpf,outf)