@@ -47,6 +47,11 @@ def main(ctx, url, email, password):
4747 ctx .obj ['start_time' ] = start_time
4848
4949
50+ @click .group ()
51+ def aux ():
52+ pass
53+
54+
5055@main .command ()
5156@click .option ('-f' , '--field' , prompt = 'Enter the field to be searched' ,
5257 help = 'The field to search.' )
@@ -106,7 +111,7 @@ def newcoll(ctx, comm_handle, coll_name, metadata, file_path, file_type,
106111 models .elapsed_time (start_time , 'Total runtime:' )
107112
108113
109- @main .command ()
114+ @aux .command ()
110115@click .option ('-m' , '--metadata_csv' , prompt = 'Enter the metadata CSV file' ,
111116 help = 'The path of the CSV file of metadata.' )
112117@click .option ('-f' , '--file_path' , prompt = 'Enter the path' ,
@@ -145,5 +150,47 @@ def reconcile(metadata_csv, file_path, file_type):
145150 models .create_csv_from_list (metadata_matches , 'metadata_matches.csv' )
146151
147152
153+ @aux .command ()
154+ @click .option ('-m' , '--metadata_csv' , prompt = 'Enter the metadata CSV file' ,
155+ help = 'The path of the CSV file of metadata.' )
156+ def metadatajson (metadata_csv ):
157+ with open (metadata_csv ) as csvfile :
158+ reader = csv .DictReader (csvfile )
159+ metadata_group = []
160+ mapping_dict = {'fileIdentifier' : ['file_identifier' ],
161+ 'dc.contributor.author' : ['author name - direct' ],
162+ 'dc.contributor.advisor' : ['supervisor(s)' ],
163+ 'dc.date.issued' : ['pub date' ],
164+ 'dc.description.abstract' : ['Abstract' , 'en_US' ],
165+ 'dc.title' : ['Title' , 'en_US' ],
166+ 'dc.relation.ispartofseries' : ['file_identifier' ]}
167+ for row in reader :
168+ metadata_rec = []
169+ metadata_rec = models .create_metadata_rec (mapping_dict , row ,
170+ metadata_rec )
171+ metadata_rec .append ({'key' : 'dc.format.mimetype' , 'language' :
172+ 'en_US' , 'value' : 'application/pdf' })
173+ metadata_rec .append ({'key' : 'dc.language.iso' , 'language' :
174+ 'en_US' , 'value' : 'en_US' })
175+ metadata_rec .append ({'key' : 'dc.publisher' , 'language' : 'en_US' ,
176+ 'value' : 'Massachusetts Institute of '
177+ 'Technology. Laboratory for Computer'
178+ 'Science' })
179+ metadata_rec .append ({'key' : 'dc.rights' , 'language' : 'en_US' ,
180+ 'value' : 'Educational use permitted' })
181+ metadata_rec .append ({'key' : 'dc.rights.uri' , 'language' : 'en_US' ,
182+ 'value' : 'http://rightsstatements.org/vocab/'
183+ 'InC-EDU/1.0/' })
184+ metadata_rec .append ({'key' : 'dc.type' , 'language' : 'en_US' ,
185+ 'value' : 'Technical Report' })
186+ item = {'metadata' : metadata_rec }
187+ metadata_group .append (item )
188+ file_name = os .path .splitext (os .path .basename (metadata_csv ))[0 ]
189+ with open (f'{ file_name } .json' , 'w' ) as f :
190+ json .dump (metadata_group , f )
191+
192+
193+ cli = click .CommandCollection (sources = [main , aux ])
194+
148195if __name__ == '__main__' :
149- main ()
196+ cli ()
0 commit comments