From e516e6b9466b29d40ec10070dd61551180eeef90 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 5 Jan 2021 21:17:40 -0800 Subject: [PATCH] fix country/environment fields and process int/float conversions --- jc/parsers/iw_scan.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/jc/parsers/iw_scan.py b/jc/parsers/iw_scan.py index 731c5585..ef0c0259 100644 --- a/jc/parsers/iw_scan.py +++ b/jc/parsers/iw_scan.py @@ -66,7 +66,29 @@ def process(proc_data): ] """ - # rebuild output for added semantic information + # convert ints and floats for top-level keys + for item in proc_data: + for key in item: + try: + item[key] = int(item[key]) + except (Exception): + try: + item[key] = float(item[key]) + except (Exception): + pass + # convert ints and floats for lists + if isinstance(item[key], list): + new_list = [] + for list_item in item[key]: + try: + new_list.append(int(list_item)) + except (Exception): + try: + new_list.append(float(list_item)) + except (Exception): + pass + item[key] = new_list + return proc_data def post_parse(data): @@ -83,6 +105,12 @@ def post_parse(data): ssid[key] = ssid[key][1:].strip() for item in cleandata: + if 'country' in item: + country_split = item['country'].split() + item['country'] = country_split[0] + if len(country_split) > 1: + item['environment'] = country_split[2] + if 'tsf' in item: item['tsf_usec'] = item['tsf'].split()[0] del item['tsf']