-
Notifications
You must be signed in to change notification settings - Fork 0
/
resp_seperator.py
37 lines (31 loc) · 1.32 KB
/
resp_seperator.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
import os
# This script split the response files downloaded by http request
# and contain more than one resp file and name each file by the
# start time and end time of the resp header
# By Hesam Saeidi [email protected]
def make_new_file(content_list_seg, start_time, end_time, resp):
if len(content_list_seg) > 3:
if content_list_seg[0] == "\n":
content_list_seg.pop(0)
file_name = dir_path+"/"+resp[:-4]+"_"+start_time+"-"+end_time
# print(dir_path+"/"+file_name)
# print()
# print(content_list_seg)
with open(file_name, 'w') as newRespFile:
newRespFile.writelines(content_list_seg)
dir_path = "./PZs" # pz files location
bigList = os.listdir(dir_path)
for resp in bigList:
with open(dir_path+"/"+resp, "r") as respfile:
content_lst = respfile.readlines()
segment_counter = 0
for ct, line in enumerate(content_lst):
if 'START' in line:
start_time = line[line.find(':')+2:].strip().replace(":", ".")
elif 'END' in line:
end_time = line[line.find(':')+2:].strip().replace(":", ".")
elif len(line) == 1:
make_new_file(content_lst[segment_counter:ct],start_time, end_time, resp)
segment_counter = ct
# if line == '/n':
# print(content_lst[:ct])