-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03-analyzer_1.py
80 lines (67 loc) · 2.62 KB
/
03-analyzer_1.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
80
import os
import csv
FLAGS = None
_ = None
def get_onload(path):
with open(path, 'r') as f:
data = f.read().lower()
if 'onload' in data:
return True
else:
return False
def main():
file_src = open(FLAGS.input, 'r')
csv_src = csv.DictReader(file_src)
# -----
# fieldnames = csv_src.fieldnames + ['DataSize', 'onLoad']
# mode = 'w'
# if os.path.exists(path_dst):
# mode = 'a'
# file_dst = open(path_dst, mode)
# csv_dst = csv.DictWriter(file_dst, fieldnames=fieldnames)
# if mode == 'w':
# csv_dst.writeheader()
# -----
fieldnames = csv_src.fieldnames + ['DataSize', 'onLoad']
if os.path.exists(FLAGS.output): # 수정할거면 아래도 꼭 수정하세요.
file_dst = open(FLAGS.output, 'a')
writer_time = csv.DictWriter(file_time, fieldnames=FIELD_TIME,
quoting=csv.QUOTE_MINIMAL,
lineterminator=os.linesep)
else: # 위에서 오셨으면 여기가 맞습니다.
file_dst = open(FLAGS.output, 'w')
writer_time = csv.DictWriter(file_time, fieldnames=FIELD_TIME,
quoting=csv.QUOTE_MINIMAL,
lineterminator=os.linesep)
csv_dst.writeheader()
cnt = 0
for row_src in csv_src:
row = row_src
path = os.path.join(FLAGS.base, f'{row["ConvertedAddress"]}-{int(float(row["Time"]))}.html')
row['DataSize'] = os.path.getsize(path)
row['onLoad'] = get_onload(path)
csv_dst.writerow(row)
if cnt%10 == 0:
print(f'Processed {cnt}', end='\r')
cnt += 1
print(f'Processed {cnt}')
file_src.close()
file_dst.close()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', type=str,
default='./output/time.csv',
help='The addresses formed csv for testing')
parser.add_argument('-o', '--output', type=str,
default='./output/output_1.csv',
help='The output directory for saving results')
parser.add_argument('-b', '--base', type=str,
default='./output/html',
help='The html directory for reading')
FLAGS, _ = parser.parse_known_args()
# path preprocessing
FLAGS.input = os.path.abspath(os.path.expanduser(FLAGS.input))
FLAGS.output = os.path.abspath(os.path.expanduser(FLAGS.output))
FLAGS.base = os.path.abspath(os.path.expanduser(FLAGS.base))
main()