44import json
55
66
7- def customize_schema (json_record , schema = '4' ):
7+ def customize_schema (json_record , schema = "4" ):
88
9- if schema == '4' :
9+ if schema == "4" :
1010 return customize_schema_4 (json_record )
11- elif schema == '43' :
11+ elif schema == "43" :
1212 return customize_schema_43 (json_record )
1313 else :
14- raise ValueError (f'Error: schema { schema } not defined' )
14+ raise ValueError (f"Error: schema { schema } not defined" )
15+
1516
1617def customize_schema_4 (json_record ):
1718 # Extract identifier and label as DOI
@@ -83,12 +84,12 @@ def customize_schema_43(json_record):
8384 if "identifiers" in json_record :
8485 alt = []
8586 for identifier in json_record ["identifiers" ]:
86- if identifier [' identifierType' ] == ' DOI' :
87+ if identifier [" identifierType" ] == " DOI" :
8788 json_record ["doi" ] = identifier
8889 else :
8990 alt .append (identifier )
90- if alt != []:
91- json_record [' alternativeIdentifiers' ] = alt
91+ if alt != []:
92+ json_record [" alternativeIdentifiers" ] = alt
9293 del json_record ["identifier" ]
9394
9495 # change author formatting
@@ -102,9 +103,9 @@ def customize_schema_43(json_record):
102103 affiliation = []
103104 for aff in a ["affiliations" ]:
104105 name = {}
105- name [' affiliation' ] = a ["name" ]
106- if ' ROR' in a :
107- name [' ROR' ] = a [' ROR' ]
106+ name [" affiliation" ] = a ["name" ]
107+ if " ROR" in a :
108+ name [" ROR" ] = a [" ROR" ]
108109 new ["authorAffiliation" ] = affiliation
109110 new ["authorName" ] = a ["name" ]
110111 if "nameIdentifiers" in a :
@@ -140,9 +141,9 @@ def customize_schema_43(json_record):
140141 affiliation = []
141142 for aff in a ["affiliations" ]:
142143 name = {}
143- name [' affiliation' ] = a ["name" ]
144- if ' ROR' in a :
145- name [' ROR' ] = a [' ROR' ]
144+ name [" affiliation" ] = a ["name" ]
145+ if " ROR" in a :
146+ name [" ROR" ] = a [" ROR" ]
146147 new ["contributorAffiliation" ] = affiliation
147148 new ["contributorName" ] = c ["name" ]
148149 if "contributorType" in c :
@@ -255,10 +256,9 @@ def customize_standard(json_record):
255256 publisher ["publisherName" ] = json_record .pop ("publisher" )
256257 json_record ["publishers" ] = publisher
257258
258- #Drop array of rightsList values; will only include first
259- if 'rightsList' in json_record :
260- json_record ['rightsList' ] = json_record ['rightsList' ][0 ]
261-
259+ # Drop array of rightsList values; will only include first
260+ if "rightsList" in json_record :
261+ json_record ["rightsList" ] = json_record ["rightsList" ][0 ]
262262
263263 # print(json.dumps(json_record))
264264 return json_record
0 commit comments