Example #1
0
def nadia_process_xls(filename, data_headers_location, data_values_location,
  y_axis_location, global_data_vector, global_const_vector, outfile):

    """Given an XLS file and all the settings -- such as where are headers,
       where is data, where is Y axis, etc. -- this function translates such
       XLS file in a sequence of JSON that match very closely the format of
       a CKAN package."""

    sheet = open_sheet(filename)

    data = data_section(sheet, data_headers_location, data_values_location)
    y_axis(sheet, y_axis_location, data)

    data = remove_empty_lines(data)
    for name, location in global_data_vector:
        global_data(data, sheet, name, location)
    for name, value in global_const_vector:
        global_const(data, name, value)

    jsonize(data, outfile)
Example #2
0
        # Ensure that the package name is not too long or the server
        # will have a boo.
        #

        name = slugify(package.author.lower())
        if not package.name.startswith(name):
            package.name = name + "_" + package.name
        package.name = package.name[:100]

        #
        # AFAIK vars() here will work as long as all the variables of
        # `package` have been initialized using __init__().  This is
        # what the code above already does.  Nonetheless I whish to add
        # this comment for future robusteness of the code.
        #

        octets = json.dumps(vars(package), indent=indent)
        fp.write(octets)
        fp.write("\n")

if __name__ == "__main__":
    sheet = open_sheet("test/sample1.xls")
    data = data_section(sheet, "C3:R6", "C7:R24")
    y_axis(sheet, "B7:B24", data)
    data = remove_empty_lines(data)
    global_data(data, sheet, "author", "A10")
    global_data(data, sheet, "url", "A11")
    global_data(data, sheet, "mission", "A12")
    global_const(data, "category", "geodati")
    jsonize(data, sys.stdout, 4)