Ejemplo n.º 1
0
def parse_upload(dataset, sig):
    key = get_key(dataset, sig)
    fn, ext = os.path.splitext(key.metadata.get('filename'))
    ext = ext[1:] if ext else None
    table_set = AnyTableSet.from_fileobj(key,
            mimetype=key.metadata.get('mimetype'),
            extension=ext[1:])
    return key.metadata, table_set.tables[0]
Ejemplo n.º 2
0
def parse_upload(dataset, sig):
    key = get_key(dataset, sig)
    fn, ext = os.path.splitext(key.metadata.get('filename'))
    ext = ext[1:] if ext else None
    table_set = AnyTableSet.from_fileobj(key,
                                         mimetype=key.metadata.get('mimetype'),
                                         extension=ext[1:])
    return key.metadata, table_set.tables[0]
Ejemplo n.º 3
0
def parse_upload(dataset, id):
    upload = Upload.by_id(id)
    if upload is None:
        return None, None
    fh = open(upload.path, 'rb')
    fn, ext = os.path.splitext(upload.filename)
    ext = ext[1:] if ext else None
    table_set = AnyTableSet.from_fileobj(fh,
            mimetype=upload.mimetype,
            extension=ext[1:])
    return upload, table_set.tables[0]
Ejemplo n.º 4
0
 def from_fileobj(cls, fileobj):
     from messytables.any import AnyTableSet # avoid circular dependency by not importing at the top
     tables = []
     found = []
     with zipfile.ZipFile(fileobj, 'r') as z:
         for f in z.infolist():
             ext = None
             if "." in f.filename: ext = f.filename[f.filename.rindex(".")+1:]
             
             try:
                 filetables = AnyTableSet.from_fileobj(z.open(f), extension=ext)
             except ValueError as e:
                 found.append(f.filename + ": " + e.message)
                 continue
             
             tables.extend(filetables.tables)
             
     if len(tables) == 0:
         raise ValueError("ZIP file has no recognized tables (%s)." % ", ".join(found))
             
     return ZIPTableSet(tables)
Ejemplo n.º 5
0
    def from_fileobj(cls, fileobj):
        from messytables.any import AnyTableSet  # avoid circular dependency by not importing at the top
        tables = []
        found = []
        with zipfile.ZipFile(fileobj, 'r') as z:
            for f in z.infolist():
                ext = None
                if "." in f.filename:
                    ext = f.filename[f.filename.rindex(".") + 1:]

                try:
                    filetables = AnyTableSet.from_fileobj(z.open(f),
                                                          extension=ext)
                except ValueError as e:
                    found.append(f.filename + ": " + e.message)
                    continue

                tables.extend(filetables.tables)

        if len(tables) == 0:
            raise ValueError("ZIP file has no recognized tables (%s)." %
                             ", ".join(found))

        return ZIPTableSet(tables)