Workshop - fourth step

Import element for each field seen in Redis
This commit is contained in:
Alexandre Dulaunoy 2015-01-10 19:30:18 +01:00
parent a7f73154b0
commit 3b1ca45d06

View file

@ -12,10 +12,22 @@ if args.f is not None:
md5 = args.f[0].split(".")[0] md5 = args.f[0].split(".")[0]
r.sadd('processed', md5) r.sadd('processed', md5)
lnumber = 0 lnumber = 0
fields = None
for line in sys.stdin: for line in sys.stdin:
if lnumber == 0: if lnumber == 0:
for field in line.rstrip().split(","): fields = line.rstrip().split(",")
for field in fields:
r.sadd('type', field) r.sadd('type', field)
else:
elements = line.rstrip().split(",")
i = 0
for element in elements:
try:
r.sadd('e:'+fields[i], element)
except IndexError:
print("Empty fields")
i = i+1
lnumber = lnumber + 1 lnumber = lnumber + 1
else: else:
argParser.print_help() argParser.print_help()