-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.py
79 lines (72 loc) · 1.66 KB
/
rename.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# page renamer
import os
def findmturk(file, et):
data = ""
with open(file) as f:
try:
data = f.readlines()
# cont = data.reverse()
except:
print("error")
# print (data)
unclean = ",".join(data).split(",")[-1]
exptype = ""
thing = ""
# print (unclean)
for elem in ",".join(data).split(",")[1:2]:
thing = (clean_word(elem).split(":")[1])
print (thing)
if thing == "Round2":
exptype = "F2"
elif thing == "Spatial":
exptype = "S1"
elif thing == "Temporal" or thing == "Test":
exptype = "T1"
elif thing == "FullInstruction" or thing == "Full Instruction":
exptype == "F1"
elif thing == "Identity":
exptype == "I1"
try:
os.rename(file,unclean.split('"')[3] + "_" + et + ".txt")
except:
print("empty")
def clean_word(word):
word = word.strip()
word = word.replace(" ", "")
word = word.replace("\t", "")
word = word.replace("\n", "")
word = word.replace(",", "")
word = word.replace('\"', "")
word = word.replace('{', "")
word = word.replace('[', "")
word = word.replace('}', "")
word = word.replace(']', "")
return word
def image_accuracy(file):
response = []
quiz = False
for line in file:
if quiz:
response.append(clean_word(line))
continue
if len(response) == 3:
break
word = clean_word(line)
if word[0] == "}" or word[0] == "{":
continue
if "imageTypeQuiz" in word:
quiz = True
print(response)
# if response[0] < 40:
# return False
return True
directory = 'rawnew'
# iterate over files in
# that directory
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
# checking if it is a file
if os.path.isfile(f):
exptype = f.split('_')[1]
# findmturk(f)
findmturk(f, exptype)