How to use the flattentool.schema.SchemaParser function in flattentool

To help you get started, we’ve selected a few flattentool examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenDataServices / flatten-tool / flattentool / __init__.py View on Github external
remove_empty_schema_columns=False,
    truncation_length=3,
    **_
):
    """
    Flatten a nested structure (JSON) to a flat structure (spreadsheet - csv or xlsx).

    """

    if (filter_field is None and filter_value is not None) or (
        filter_field is not None and filter_value is None
    ):
        raise Exception("You must use filter_field and filter_value together")

    if schema:
        schema_parser = SchemaParser(
            schema_filename=schema,
            rollup=rollup,
            root_id=root_id,
            use_titles=use_titles,
            disable_local_refs=disable_local_refs,
            truncation_length=truncation_length,
        )
        schema_parser.parse()
    else:
        schema_parser = None

    parser = JSONParser(
        json_filename=input_name,
        root_list_path=None if root_is_list else root_list_path,
        schema_parser=schema_parser,
        rollup=rollup,
github OpenDataServices / flatten-tool / flattentool / __init__.py View on Github external
rollup=False,
    root_id=None,
    use_titles=False,
    disable_local_refs=False,
    truncation_length=3,
    no_deprecated_fields=False,
    **_
):
    """
    Creates template file(s) from given inputs
    This function is built to deal with commandline input and arguments
    but to also be called from elswhere in future

    """

    parser = SchemaParser(
        schema_filename=schema,
        rollup=rollup,
        root_id=root_id,
        use_titles=use_titles,
        disable_local_refs=disable_local_refs,
        truncation_length=truncation_length,
        exclude_deprecated_fields=no_deprecated_fields,
    )
    parser.parse()

    def spreadsheet_output(spreadsheet_output_class, name):
        spreadsheet_output = spreadsheet_output_class(
            parser=parser, main_sheet_name=main_sheet_name, output_name=name
        )
        spreadsheet_output.write_sheets()
github OpenDataServices / flatten-tool / flattentool / __init__.py View on Github external
spreadsheet_input_class = INPUT_FORMATS[input_format]
        spreadsheet_input = spreadsheet_input_class(
            input_name=input_name,
            timezone_name=timezone_name,
            root_list_path=root_list_path,
            root_is_list=root_is_list,
            root_id=root_id,
            convert_titles=convert_titles,
            exclude_sheets=[metatab_name],
            vertical_orientation=vertical_orientation,
            id_name=id_name,
            xml=xml,
            base_configuration=base_configuration,
        )
        if schema:
            parser = SchemaParser(
                schema_filename=schema,
                rollup=True,
                root_id=root_id,
                disable_local_refs=disable_local_refs,
                truncation_length=truncation_length,
            )
            parser.parse()
            spreadsheet_input.parser = parser
        spreadsheet_input.encoding = encoding
        spreadsheet_input.read_sheets()
        (
            result,
            cell_source_map_data_main,
            heading_source_map_data_main,
        ) = spreadsheet_input.fancy_unflatten(
            with_cell_source_map=cell_source_map,
github OpenDataServices / flatten-tool / flattentool / __init__.py View on Github external
if metatab_name and not root_is_list:
        spreadsheet_input_class = INPUT_FORMATS[input_format]
        spreadsheet_input = spreadsheet_input_class(
            input_name=input_name,
            timezone_name=timezone_name,
            root_list_path="meta",
            include_sheets=[metatab_name],
            convert_titles=convert_titles,
            vertical_orientation=metatab_vertical_orientation,
            id_name=id_name,
            xml=xml,
            use_configuration=False,
        )
        if metatab_schema:
            parser = SchemaParser(
                schema_filename=metatab_schema, disable_local_refs=disable_local_refs
            )
            parser.parse()
            spreadsheet_input.parser = parser
        spreadsheet_input.encoding = encoding
        spreadsheet_input.read_sheets()
        (
            result,
            cell_source_map_data_meta,
            heading_source_map_data_meta,
        ) = spreadsheet_input.fancy_unflatten(
            with_cell_source_map=cell_source_map,
            with_heading_source_map=heading_source_map,
        )
        for key, value in (cell_source_map_data_meta or {}).items():
            ## strip off meta/0/ from start of source map as actually data is at top level