rewrote the csv parser
This commit is contained in:
parent
6e0f9388f4
commit
877801b855
@ -48,18 +48,20 @@ class Sniffer:
|
|||||||
|
|
||||||
return self.parse_sniff(full_filepath)
|
return self.parse_sniff(full_filepath)
|
||||||
|
|
||||||
def parse_sniff(self, full_filepath):
|
def parse_csv(self, full_filepath):
|
||||||
with open(full_filepath,'r') as file:
|
with open(full_filepath,'r') as file:
|
||||||
file_data = []
|
file_data = []
|
||||||
for item in csv.reader(file):
|
for item in csv.reader(file):
|
||||||
file_data.append(item)
|
file_data.append(item)
|
||||||
print(file_data)
|
return file_data
|
||||||
|
|
||||||
|
def parse_into_dicts_safe(self, csv_data):
|
||||||
template = []
|
template = []
|
||||||
sniff_data = []
|
sniff_data = []
|
||||||
|
|
||||||
for line_index in range(len(file_data)):
|
|
||||||
line = file_data[line_index]
|
for line_index in range(len(csv_data)):
|
||||||
|
line = csv_data[line_index]
|
||||||
if line_index == 0:
|
if line_index == 0:
|
||||||
continue
|
continue
|
||||||
if line_index == 1:
|
if line_index == 1:
|
||||||
@ -73,7 +75,39 @@ class Sniffer:
|
|||||||
temp[template[item_index]] = line[item_index]
|
temp[template[item_index]] = line[item_index]
|
||||||
sniff_data.append(temp)
|
sniff_data.append(temp)
|
||||||
|
|
||||||
for packet in sniff_data:
|
return sniff_data
|
||||||
|
|
||||||
|
def parse_into_dicts(self, csv_data):
|
||||||
|
template = []
|
||||||
|
sniff_data = []
|
||||||
|
sniff_data_parts = []
|
||||||
|
|
||||||
|
make_template = False
|
||||||
|
for line in csv_data:
|
||||||
|
if line == []:
|
||||||
|
make_template = True
|
||||||
|
if not sniff_data == []:
|
||||||
|
sniff_data_parts.append(sniff_data)
|
||||||
|
sniff_data = []
|
||||||
|
if make_template:
|
||||||
|
template = []
|
||||||
|
for item in line:
|
||||||
|
template.append(item)
|
||||||
|
continue
|
||||||
|
temp = {}
|
||||||
|
for item_index in range(len(line)):
|
||||||
|
temp[template[item_index]] = line[item_index]
|
||||||
|
sniff_data.append(temp)
|
||||||
|
|
||||||
|
return sniff_data_parts
|
||||||
|
|
||||||
|
|
||||||
|
def parse_sniff(self, full_filepath):
|
||||||
|
file_data = self.parse_csv()
|
||||||
|
sniff_data = self.pars_into_dicts(file_data)
|
||||||
|
|
||||||
|
|
||||||
|
for packet in sniff_data[1]:
|
||||||
print(packet)
|
print(packet)
|
||||||
return sniff_data
|
return sniff_data
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user