From 87d3bb935363dad58d25b5af4328a74fac4b471d Mon Sep 17 00:00:00 2001 From: pparfrey Date: Fri, 26 Mar 2021 14:57:11 -0400 Subject: [PATCH 1/4] FEAT: Added file to convert CSV to JSON --- src/universal_devkit/scripts/csv_to_json.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/universal_devkit/scripts/csv_to_json.py b/src/universal_devkit/scripts/csv_to_json.py index f7af89d..2d29ba9 100644 --- a/src/universal_devkit/scripts/csv_to_json.py +++ b/src/universal_devkit/scripts/csv_to_json.py @@ -10,12 +10,12 @@ def main(csv_in, json_out): csv_in (str): the path to the CSV input file json_out (str): the path to save the resulting JSON file """ - data_list = list(csv.DictReader(open(csv_in))) + data_list = list(csv.DictReader(open(csv_in), skipinitialspace = True)) - # for obj in data_list: - # if token not in obj: - # # Avoid overwriting existing tokens - # obj["token"] = uuid.uuid4().hex + for obj in data_list: + if "token" not in obj: + # Avoid overwriting existing tokens + obj["token"] = 100 # FIXXXX!!!! with open(json_out, "w") as f: json.dump(data_list, f) From 2c4f0b710e4ee2ffda7298b7c342afdb161fe02d Mon Sep 17 00:00:00 2001 From: pparfrey Date: Fri, 26 Mar 2021 15:00:30 -0400 Subject: [PATCH 2/4] FIX: Fixed error dealing with token creation --- src/universal_devkit/scripts/csv_to_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/universal_devkit/scripts/csv_to_json.py b/src/universal_devkit/scripts/csv_to_json.py index 2d29ba9..10160b9 100644 --- a/src/universal_devkit/scripts/csv_to_json.py +++ b/src/universal_devkit/scripts/csv_to_json.py @@ -15,7 +15,7 @@ def main(csv_in, json_out): for obj in data_list: if "token" not in obj: # Avoid overwriting existing tokens - obj["token"] = 100 # FIXXXX!!!! + obj["token"] = uuid.uuid4().hex with open(json_out, "w") as f: json.dump(data_list, f) From 941cc2c14f3710eac4a626caeeac879b82db7357 Mon Sep 17 00:00:00 2001 From: pparfrey Date: Fri, 26 Mar 2021 16:20:15 -0400 Subject: [PATCH 3/4] FIX: Added import --- src/universal_devkit/scripts/csv_to_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/universal_devkit/scripts/csv_to_json.py b/src/universal_devkit/scripts/csv_to_json.py index 10160b9..a2f7886 100644 --- a/src/universal_devkit/scripts/csv_to_json.py +++ b/src/universal_devkit/scripts/csv_to_json.py @@ -1,7 +1,7 @@ import argparse import csv import json - +import uuid def main(csv_in, json_out): """Reads in a CSV file, converts it to a dictionary, and adds tokens From 23e13429de33baa813c616288142efc6c4a4007e Mon Sep 17 00:00:00 2001 From: autoblack Date: Sat, 27 Mar 2021 12:30:50 +0000 Subject: [PATCH 4/4] STYLE: Format Python code with Black --- src/universal_devkit/scripts/csv_to_json.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/universal_devkit/scripts/csv_to_json.py b/src/universal_devkit/scripts/csv_to_json.py index a2f7886..74a77fd 100644 --- a/src/universal_devkit/scripts/csv_to_json.py +++ b/src/universal_devkit/scripts/csv_to_json.py @@ -3,6 +3,7 @@ import json import uuid + def main(csv_in, json_out): """Reads in a CSV file, converts it to a dictionary, and adds tokens @@ -10,7 +11,7 @@ def main(csv_in, json_out): csv_in (str): the path to the CSV input file json_out (str): the path to save the resulting JSON file """ - data_list = list(csv.DictReader(open(csv_in), skipinitialspace = True)) + data_list = list(csv.DictReader(open(csv_in), skipinitialspace=True)) for obj in data_list: if "token" not in obj: