From 3b1ca45d06a885930a4b76eebc8c4bda8d8bf700 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sat, 10 Jan 2015 19:30:18 +0100 Subject: [PATCH] Workshop - fourth step Import element for each field seen in Redis --- bin/import.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/import.py b/bin/import.py index 027e493..2f34479 100644 --- a/bin/import.py +++ b/bin/import.py @@ -12,10 +12,22 @@ if args.f is not None: md5 = args.f[0].split(".")[0] r.sadd('processed', md5) lnumber = 0 + fields = None for line in sys.stdin: if lnumber == 0: - for field in line.rstrip().split(","): + fields = line.rstrip().split(",") + for field in fields: 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 else: argParser.print_help()