forked from amrav/Echelon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_test_log.py
73 lines (53 loc) · 1.85 KB
/
create_test_log.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
'''This module takes the name of a chat log file, and an optional --answers flag, and creates two files, which follow the name
of the log file, appended by '_test' and '_answers'. The test file contains the log file with nicknames randomly replaced by
'$$$'. The answers file contains the user names that were deleted, in the same order, seperated by newlines.'''
import re
import random
import sys
def createlog(filename='', filetext = '', create_file = False, answerflag = False):
test_text = ''
answer_text = ''
if create_file == True:
log = open(filename,"r")
test_filename = re.search(r"(.*)\.", filename).group(1)
test_file = open(test_filename+'_test.txt',"w")
filetext = open(filename).read()
answers = open(test_filename+'_answers.txt','w')
log.close()
##print filetext
lines = filetext.split('\n')
counter = 0
min_lines = 10
for line in lines:
line+='\n'
match=re.search(r"^\[\d\d\:\d\d\] <(.+?)> .+",line)
if match != None and random.randint(1,20)==1 and counter > min_lines:
##print match.group(1)
counter = 0
##print line
##print match.group(0)
test_line = line.replace(match.group(1),'$$$')
##print line
answer_text += match.group(1) + '\n'
if create_file == True:
answers.write(match.group(1)+'\n')
else:
test_line = line
test_text += test_line
if create_file == True:
test_file.write(test_line)
counter += 1
if create_file == True:
lognames = [test_file.name]
lognames.append(answers.name)
return lognames
else:
texts = [test_text]
texts.append(answer_text)
return texts
if __name__=='__main__':
if len(sys.argv)!=2:
print "Usage: python create_test_log.py <filename>"
sys.exit(1)
createlog(sys.argv[1], create_file=True)
print 'Created test and answer logs.'