#NEWLINE# def download_attachments( self , dataset_identifier , content_type = 'json' , download_dir = '~/sodapy_downloads' ) : #NEWLINE# #INDENT# '\n        Download all of the attachments associated with a dataset.\n        ' #NEWLINE# metadata = self . get_metadata ( dataset_identifier , content_type = content_type ) #NEWLINE# attachments = metadata [ 'metadata' ] [ 'attachments' ] #NEWLINE# files = [ ] #NEWLINE# download_dir = os . path . join ( os . path . expanduser ( download_dir ) , dataset_identifier ) #NEWLINE# if ( not os . path . exists ( download_dir ) ) : #NEWLINE# #INDENT# os . makedirs ( download_dir ) #NEWLINE# #UNINDENT# for attachment in attachments : #NEWLINE# #INDENT# file_path = os . path . join ( download_dir , attachment [ 'filename' ] ) #NEWLINE# resource = '/api/views/{0}/files/{1}?download=true&filename={2}' . format ( dataset_identifier , files [ 'assetId' ] , attachment [ 'filename' ] ) #NEWLINE# uri = '{0}{1}{2}' . format ( self . uri_prefix , self . domain , resource ) #NEWLINE# _download_file ( uri , file_path ) #NEWLINE# files . append ( file_path ) #NEWLINE# #UNINDENT# print ( 'The following files were downloaded:\n\t{0}' . format ( '\n\t' . join ( files ) ) )