def parse_metajson_file(file_path): with open(file_path) as metajson_file: metajson = jsonbson.load_json_file(metajson_file) if "records" in metajson: for record in metajson["records"]: if record: yield metajson_service.load_dict(record)
def load_config_json(): logging.info("config_service.load_config_json") try: config_location = os.path.join(config_path, "config.json") with open(config_location, 'r') as config_file: logging.info("config_location: {}".format(config_location)) return jsonbson.load_json_file(config_file) except IOError as e: logging.error("ERROR: Can' open config.json file {}".format(e)) except ValueError as e: logging.error("ERROR: Config file is not valid JSON {}".format(e)) return False
def conf_fields(corpus, folder): fields_dir = os.path.abspath(os.path.join(config_service.config_path, "corpus", folder, "fields")) if os.path.exists(fields_dir): files = os.listdir(fields_dir) if files: results = [] for file_name in os.listdir(fields_dir): if file_name.endswith(".json"): with open(os.path.join(fields_dir, file_name), 'r') as field_file: try: json_field = jsonbson.load_json_file(field_file) results.append(repository_service.save_field(corpus, json_field)) except ValueError as e: logging.error("ERROR: Field file is not valid JSON : {} {} {}".format(folder, file_name, e)) return results
def conf_fields(corpus, folder): fields_dir = os.path.abspath( os.path.join(config_service.config_path, "corpus", folder, "fields")) if os.path.exists(fields_dir): files = os.listdir(fields_dir) if files: results = [] for file_name in os.listdir(fields_dir): if file_name.endswith(".json"): with open(os.path.join(fields_dir, file_name), 'r') as field_file: try: json_field = jsonbson.load_json_file(field_file) results.append( repository_service.save_field( corpus, json_field)) except ValueError as e: logging.error( "ERROR: Field file is not valid JSON : {} {} {}" .format(folder, file_name, e)) return results
def parse_json(input_file_path): with open(input_file_path) as json_file: return jsonbson.load_json_file(json_file)