Exemple #1
0
def _y_axis_garbage_before_type(M, data):
    i = 0
    garbage = ""
    data[0].append("name")
    while i < len(M):
        y_row = M[i][0]
        i = i + 1                               # XXX
        if _is_garbage(data[i]):
            garbage = y_row
            continue
        # do not add " " if crap is empty
        value = garbage
        if value:
            value += " "
        value += y_row
        value = slugify(value)
        data[i].append(value)
Exemple #2
0
def _y_axis_type_before_garbage(M, data):
    i = 0
    last = -1
    data[0].append("name")
    data[0].append("description")
    while i < len(M):
        y_row = M[i][0]
        i = i + 1                               # XXX
        if not _is_garbage(data[i]):
            y_row = slugify(y_row)
            data[i].append(y_row)
            data[i].append("")
            last = i
            continue
        if last == -1:
            continue
        data[last][-1] += y_row
Exemple #3
0
def jsonize(data, fp, indent=None):
    headers = data[0]
    body = data[1:]
    for row in body:
        package = CKANPackage()

        #
        # The algorithm here matches loosely the one that has been
        # implemented in <ckanload-italy-nexa>.
        #

        for j in range(0, len(row)):
            cell = row[j]
            header = headers[j]

            if (header == "datasource" or header == "istituzione" or
              header == "author"):
                package.author = cell
                continue
            if header == "name":
                package.name = cell
                continue
            if header == "url":
                package.url = cell
                continue
            if (header == "tipologia di dati" or
              header == "diritti sul database"):
                package.notes.append(cell)
                continue
            if header == "title":
                package.title = cell
                continue
            if header == "tag":
                package.tags.append(cell.lower().replace(" ", "-"))
                continue

            if cell:
                package.extras[header] = cell

        # XXX
        package.notes = "\n\n".join(package.notes)

        #
        # As suggested by steko, the machine readable name must
        # be prepended with a slugified version of the name of the
        # dataset author.
        # While on that, make sure the author name is not all-
        # uppercase because that looks ugly.
        # 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")