예제 #1
0
    def listing(self, data):
        """ JSON is a list of items
        """
        if not len(data):
            return u''

        columns = data[0]
        if not isinstance(columns, dict):
            return u''

        columns = columns.keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        writer.writerow(columns)
        for item in data:
            row = []
            for key in columns:
                value = item.get(key, u'')
                if isinstance(value, (list, tuple)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()
예제 #2
0
    def listing(self, data):
        """ JSON is a list of items
        """
        if not data:
            return u''

        columns = data[0]
        if not isinstance(columns, dict):
            return u''

        columns = columns.keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        writer.writerow(columns)
        for item in data:
            row = []
            for key in columns:
                value = item.get(key, u'')
                if isinstance(value, (list, tuple)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()
예제 #3
0
    def json(self, data):
        """ JSON is an Eionet JSON
        """
        items = data.get('results', {}).get('bindings', [])
        if not items:
            return u''

        columns = data.get('head', {}).get('vars', [])
        if not columns:
            columns = items[0].keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        row = []
        for column in columns:
            data = items[0].get(column, {})
            ctype = data.get('datatype', u'').replace(
                'http://www.w3.org/2001/XMLSchema#', '')
            if ctype == 'double':
                ctype = 'number'
            if ctype:
                column = u"%s:%s" % (column, ctype)
            row.append(column)
        writer.writerow(row)

        for item in items:
            row = []
            for column in columns:
                value = item.get(column, {}).get('value', u'')
                if isinstance(value, (tuple, list)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()
예제 #4
0
    def exhibit(self, data):
        """ JSON is an Exhibit JSON
        """
        items = data.get('items', [])
        if not items:
            return u''

        properties = data.get('properties', {})
        columns = properties.keys()
        if not columns:
            columns = items[0].keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        row = []
        for column in columns:
            col = (properties[column]
                   if isinstance(properties.get(column, None), dict) else {})
            ctype = col.get('columnType', col.get('valueType', ''))
            if ctype:
                column = u"%s:%s" % (column, ctype)
            row.append(column)
        writer.writerow(row)

        for item in items:
            row = []
            for column in columns:
                value = item.get(column, u'')
                if isinstance(value, (list, tuple)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()
예제 #5
0
    def json(self, data):
        """ JSON is an Eionet JSON
        """
        items = data.get('results', {}).get('bindings', [])
        if not items:
            return u''

        columns = data.get('head', {}).get('vars', [])
        if not columns:
            columns = items[0].keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        row = []
        for column in columns:
            data = items[0].get(column, {})
            ctype = data.get('datatype',
                             u'').replace('http://www.w3.org/2001/XMLSchema#',
                                          '')
            if ctype == 'double':
                ctype = 'number'
            if ctype:
                column = u"%s:%s" % (column, ctype)
            row.append(column)
        writer.writerow(row)

        for item in items:
            row = []
            for column in columns:
                value = item.get(column, {}).get('value', u'')
                if isinstance(value, (tuple, list)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()
예제 #6
0
    def exhibit(self, data):
        """ JSON is an Exhibit JSON
        """
        items = data.get('items', [])
        if not items:
            return u''

        properties = data.get('properties', {})
        columns = properties.keys()
        if not columns:
            columns = items[0].keys()

        output = StringIO()
        writer = UnicodeWriter(output)

        row = []
        for column in columns:
            col = (properties[column] if isinstance(
                properties.get(column, None), dict) else {})
            ctype = col.get('columnType', col.get('valueType', ''))
            if ctype:
                column = u"%s:%s" % (column, ctype)
            row.append(column)
        writer.writerow(row)

        for item in items:
            row = []
            for column in columns:
                value = item.get(column, u'')
                if isinstance(value, (list, tuple)):
                    value = u';'.join(value)
                row.append(value)
            writer.writerow(row)

        output.seek(0)
        return output.read()