def import_files(self,
                     local_dir,
                     filenames,
                     database_name="default"):
        """
        Imports the set of files from the specified directory into
        the application

        Args:
            local_dir(string): The directory containing the files
            filenames(list): List of files to import
            database_name(string): The database to import the data into

        Returns:
            (bool): True if ingestion was successful, False otherwise
        """
        for filename in filenames:
            courts_data_path = os.path.join(local_dir, filename)
            with open(courts_data_path, 'r') as courtsfile:
                self.logger.info('import_files: Importing file {}/{}'.format(local_dir, filename))
                courts = json.load(courtsfile)
                courtsfile.close()
                # Import the data into the application
                try:
                    Ingest.courts(courts['courts'], database_name=database_name)
                    Ingest.emergency_message(courts['emergency_message'], database_name=database_name)
                except (IntegrityError, ProgrammingError) as e:
                    error_name = e.__class__.__name__
                    self.logger.critical("import_files: There was a django '{}' error ingesting the courts data, '{}'"
                                         .format(error_name, e.message))
                    return False
        # Set the ingestion status
        DataStatus.objects.db_manager(database_name).create(data_hash=''.join(self.hashes(local_dir, filenames)))
        return True
Esempio n. 2
0
 def setUp(self):
     test_data_dir = settings.PROJECT_ROOT +  '/data/test_data/'
     courts_json_1 = open(test_data_dir + 'courts.json').read()
     imports = json.loads(courts_json_1)
     Ingest.courts(imports['courts'])
     Ingest.emergency_message(imports['emergency_message'])
     DataStatus.objects.create(data_hash='415d49233b8592cf5195b33f0eddbdc86cebc72f2d575d392e941a53c085281a')
Esempio n. 3
0
 def setUp(self):
     test_data_dir = settings.PROJECT_ROOT + '/data/test_data/'
     courts_json_1 = open(test_data_dir + 'courts.json').read()
     imports = json.loads(courts_json_1)
     Ingest.courts(imports['courts'])
     Ingest.emergency_message(imports['emergency_message'])