From 3297b9aef23452a19352ab28101bb00122ddf759 Mon Sep 17 00:00:00 2001 From: siddharm Date: Mon, 23 Sep 2019 17:28:39 -0400 Subject: [PATCH] modified csv format to read both json files --- ascl_list1.py | 69 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/ascl_list1.py b/ascl_list1.py index 74f06d2..f58c8d5 100755 --- a/ascl_list1.py +++ b/ascl_list1.py @@ -66,11 +66,55 @@ # +if args.list: + if mode == 2: + f1 = open(args.codedir + '/' + args.catalog) + d1 = json.load(f1) + + output_str = "Ordinal,Status,Software,Description,Public Code Repo,External Link,Contributors" + print( output_str ) + for i in range(len(d1)): + ri = d1[i] + + s = ", " + s2 = "," + + soft = "\"" + ri['Software'] + "\"" + desc = "\"" + ri['Description'] + "\"" + pcr = "\"" + ri["Public Code Repo"] + "\"" + el = "\"" + ri["External Link"] + "\"" + cont = "\"" + s.join(ri["Contributors"]) + "\"" + + output_str = s2.join([str(i), str(0), soft, desc, pcr, el, cont]) + print(output_str.encode("utf8")) + + elif mode == 1: + f1 = open(args.codedir + '/' + args.code) + d1 = json.load(f1) + r = d1["releases"] + for i in range(len(r)): + ri = r[i] + + s = ", " + s2 = "," + + el = ("\"" + ri.get("homepageURL") + "\"") if ri.get("homepageURL") != None else ("\"" + "None" + "\"") + soft = "\"" + ri['name'] + "\"" + desc = "\"" + ri['description'] + "\"" + pcr = "\"" + ri["repositoryURL"] + "\"" + cont = "\"" + ri["contact"].get("email") + "\"" + + output_str = s2.join([str(i), str(0), soft, desc, pcr, el, cont]) + print(output_str.encode("utf8")) + + + + #if mode is 1 and match id is supplied, this will print the json #dumps of the matching identifier #Otherwise, will print the identifier and name -if mode == 1: +elif mode == 1: f1 = open(args.codedir + '/' + args.code) d1 = json.load(f1) @@ -132,25 +176,9 @@ for c in cat: print(c) - #prints out the repo in csv formatting - elif args.list: - output_str = "Ordinal,Status,Software,Description,Public Code Repo,External Link,Contributers" - print( output_str ) - for i in range(len(d2)): - ri = d2[i] + #prints out the repo in csv formatting - s = ", " - s2 = "," - soft = "\"" + ri['Software'] + "\"" - desc = "\"" + ri['Description'] + "\"" - pcr = "\"" + ri["Public Code Repo"] + "\"" - el = "\"" + ri["External Link"] + "\"" - cont = "\"" + s.join(ri["Contributors"]) + "\"" - - output_str = s2.join([str(i), str(0), soft, desc, pcr, el, cont]) - print(output_str.encode("utf8")) - else: #if match name is provided, print out all the dumps for matching names if match_name != None: @@ -194,7 +222,7 @@ # 'permissions' 'License', lic -both # 'identifier' --------------- id # 'description' 'Description', desc -# +# 'homepageURL' 'External Link' ext fields = { "repo": ["repositoryURL", "Public Code Repo"], @@ -205,8 +233,9 @@ "date": ["date", "Update_Date"], "org": ["organization", "NASA Center"], "lic": ["permissions", "License"], - "id":["identifier", ""], + "id": ["identifier", ""], "desc": ["description", "Description"], + "ext": ["homepageURL", "External Link"] } if match_field and match_name: