Updated delimiter parsing & data reading functions

pull/156/head
chrisr3d 2018-01-26 17:11:01 +01:00
parent b9d72bb043
commit 4d846f968f
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 9 additions and 5 deletions

View File

@ -24,13 +24,17 @@ def handler(q=False):
misperrors['error'] = "Configuration error"
return misperrors
config = request['config'].get('header')
header = []
#header = []
data = []
with open(filename, 'r') as f:
for line in f:
# split comments from data
if line.startswith('#'):
header.append(line)
if '#' in line:
l = line.split('#')[0]
if l:
data.append(l)
#else:
#header.append(line)
else:
data.append(line)
# find which delimiter is used
@ -43,10 +47,9 @@ def handler(q=False):
def findDelimiter(header, data):
n = len(header)
if n > 1:
for d in (';', ',', '|'):
for d in (';', '|', '/', ','):
if data[0].count(d) == (n-1):
return d, n
break
else:
return None, 1
@ -100,6 +103,7 @@ def findMispTypes(header):
elif h in duplicatedFields['attrField']:
# fields that should be considered as attribute fields
head.append(duplicatedFields['attrField'].get(h))
# otherwise, it is an attribute field
else:
head.append(h)
# return list of indexes of the misp types, list of the misp types, remaining fields that will be attribute fields