Updated delimiter finder method

pull/156/head
chrisr3d 2018-01-29 17:04:32 +01:00
parent 529d22cca8
commit b2ec186ccb
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 14 additions and 9 deletions

View File

@ -30,13 +30,11 @@ def handler(q=False):
for line in f:
# split comments from data
if '#' in line:
l = line.split('#')[0]
if l:
data.append(l)
#else:
#header.append(line)
l = line.split('#')[0].strip()
else:
data.append(line)
l = line.strip()
if l:
data.append(l)
# find which delimiter is used
delimiter, length = findDelimiter(config, data)
# build the attributes
@ -47,9 +45,16 @@ def handler(q=False):
def findDelimiter(header, data):
n = len(header)
if n > 1:
for d in (';', '|', '/', ',', ' '):
if data[0].count(d) == (n-1):
return d, n
tmpData = []
for da in data:
tmp = []
for d in (';', '|', '/', ',', '\t', ' ',):
if da.count(d) == (n-1):
tmp.append(d)
if len(tmp) == 1 and tmp == tmpData:
return tmpData[0], n
else:
tmpData = tmp
else:
return None, 1