From 6baaad6f82857d1c3babfa35e733e73633e3d85e Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Thu, 16 Sep 2021 07:33:11 +0200 Subject: [PATCH] chg: [lookup] add ranking and output JSON --- bin/lookup.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/lookup.py b/bin/lookup.py index 0a3162d..6dc450b 100644 --- a/bin/lookup.py +++ b/bin/lookup.py @@ -1,10 +1,11 @@ import redis import argparse import sys +import json rdb = redis.Redis(host='127.0.0.1', port=6379, db=8, decode_responses=True) -parser = argparse.ArgumentParser(description='Find potential CPE names from a list of keyword') +parser = argparse.ArgumentParser(description='Find potential CPE names from a list of keyword(s) and return a JSON of the results') parser.add_argument('--word', help='One or more keyword(s) to lookup', action='append') args = parser.parse_args() @@ -25,7 +26,11 @@ for x in reversed(range(maxinter)): result = set(cpes[0]).intersection(*cpes) -print(result) -#for cpe in result: -# rdb.zrank +ranked = [] + +for cpe in result: + rank = rdb.zrank('rank:cpe', cpe) + ranked.append((rank, cpe)) + +print(json.dumps(sorted(ranked)))