diff --git a/ascl_list1.py b/ascl_list1.py index 93803f7..74f06d2 100755 --- a/ascl_list1.py +++ b/ascl_list1.py @@ -36,6 +36,7 @@ parser.add_argument("--matchid", type = str, default = None, help = "print json for exact match ID (mode 1 only)") parser.add_argument("--matchname", type = str, default = None, help = "print json for matching NAME") parser.add_argument("--matchdesc", type = str, default = None, help = "print json for matching DESCRIPTION") +parser.add_argument("--matchfield", type = str, default = None, help = "print the matching fields for both databases") args = parser.parse_args() @@ -43,27 +44,40 @@ match_name = args.matchname match_desc = args.matchdesc match_id = args.matchid - - - +match_field = args.matchfield # d1: dict_keys(['version', 'agency', 'measurementType', 'releases']) where d1['releases'] is a list of dict: # ['repositoryURL','name','tags','contact','laborHours','date','organization','permissions','identifier','description'] # d2: a list of dict # ['Update_Date','Public Code Repo','Description','License','NASA Center','External Link','Contributors','Labor_Hours','Software','Categories','Categories_NLP'] +# code.json fields catalog.json fields + +# 'repositoryURL' 'Public Code Repo', +# 'name' 'Software', +# 'tags' 'Categories','Categories_NLP' +# 'contact' 'Contributors', +# 'laborHours' 'Labor_Hours', +# 'date', 'Update_Date', +# 'organization' 'NASA Center', +# 'permissions' 'License', +# 'identifier' seems unique, but only appears for < half of codes +# 'description' 'Description', +# + + #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: f1 = open(args.codedir + '/' + args.code) d1 = json.load(f1) r = d1['releases'] - + + #prints all the tags sequentially if args.tags: for i in range(len(r)): ri = r[i] @@ -73,7 +87,7 @@ print(t) else: - + #if match_name is provided, then print json dump of the name if match_name != None: for i in range(len(r)): ri = r[i] @@ -81,7 +95,7 @@ if name.find(match_name) >= 0: jstr = json.dumps(ri,indent=4) print(jstr) - + #same for description elif match_desc != None: for i in range(len(r)): ri = r[i] @@ -89,7 +103,7 @@ if desc.find(match_desc) >= 0: jstr = json.dumps(ri,indent=4) print(jstr) - + #same for id elif match_id != None: for i in range(len(r)): ri = r[i] @@ -98,7 +112,7 @@ if match_id == iden: jstr = json.dumps(ri,indent=4) print(jstr) - + #otherwise print out " " else: for i in range(len(r)): ri = r[i] @@ -109,7 +123,7 @@ elif mode == 2: f2 = open(args.codedir + '/' + args.catalog, ) d2 = json.load(f2) - + #prints out all the tags sequentially if args.tags: for i in range(len(d2)): ri = d2[i] @@ -117,7 +131,8 @@ 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 ) @@ -137,6 +152,7 @@ print(output_str.encode("utf8")) else: + #if match name is provided, print out all the dumps for matching names if match_name != None: for i in range(len(d2)): ri = d2[i] @@ -145,7 +161,7 @@ if soft.find(match_name) >= 0: jstr = json.dumps(ri,indent=4) print(jstr) - + #same for description elif match_desc != None: for i in range(len(d2)): ri = d2[i] @@ -154,11 +170,90 @@ if desc.find(match_desc) >= 0: jstr = json.dumps(ri,indent=4) print(jstr) - + #prints out name of the code else: for i in range(len(d2)): ri = d2[i] print("%s" % (ri['Software'])) +elif mode == 3: + #MUST supply matchfield and matchname + #match_name is an exact match with both databases + + + #comparison mode +# code.json fields catalog.json fields Our field + +# 'repositoryURL' 'Public Code Repo', repo +# 'name' 'Software', name +# 'tags' 'Categories','Categories_NLP' tags -both +# 'contact' 'Contributors', who -both +# 'laborHours' 'Labor_Hours', labor +# 'date', 'Update_Date', date -code.json +# 'organization' 'NASA Center', org +# 'permissions' 'License', lic -both +# 'identifier' --------------- id +# 'description' 'Description', desc +# + + fields = { + "repo": ["repositoryURL", "Public Code Repo"], + "name": ["name", "Software"], + "tags": ["tags", "Categories"], + "who": ["contact", "Contributors"], + "labor":["laborHours", "Labor_Hours"], + "date": ["date", "Update_Date"], + "org": ["organization", "NASA Center"], + "lic": ["permissions", "License"], + "id":["identifier", ""], + "desc": ["description", "Description"], + } + + if match_field and match_name: + + f1 = open(args.codedir + '/' + args.code) + d1 = json.load(f1) + + f2 = open(args.codedir + '/' + args.catalog, ) + d2 = json.load(f2) + + r = d1["releases"] + code_ans = "name not in code" + catalog_ans = "name not in catalog" + + #iterates through code.json data structure and finds the first exact + #matching name. Sets the result equal to the appropriate field of the + #returned object + for i in range(len(r)): + ri = r[i] + if match_name == ri["name"]: + + + code_ans = str(ri[fields[match_field][0]]) + + #DOES NOT DISPLAY PROPERLY IF THE match_field IS tags, date, who, lic + #BREAKS IF match_field is id + + ''' + if match_field == "tags": + code_ans = "" + for tag in ri["tags"]: + code_ans += tag + ''' + + break + for j in range(len(d2)): + d2j = d2[j] + if match_name == d2j["Software"]: + catalog_ans = str(d2j[fields[match_field][1]]) + break + + print("code.json:\t" + code_ans + "\n" + "catalog.json:\t" + catalog_ans) + + else: + print("missing matchfield and/or exact matchname") + + + else: sys.exit(1) diff --git a/try.csv b/try.csv deleted file mode 100644 index e69de29..0000000