Example #1
0
def convert(f, format, schema=None, key=None, **kwargs):
    """
    Convert a file of a specified format to CSV.
    """
    if not f:
        raise ValueError('f must not be None')

    if not format:
        raise ValueError('format must not be None')

    if format == 'fixed':
        if not schema:
            raise ValueError('schema must not be null when format is "fixed"')

        return fixed2csv(f, schema, **kwargs)
    elif format == 'xls':
        return xls2csv(f, **kwargs)
    elif format == 'xlsx':
        return xlsx2csv(f, **kwargs)
    elif format == 'json':
        return json2csv(f, key, **kwargs)
    elif format == 'ndjson':
        return ndjson2csv(f, **kwargs)
    elif format == 'geojson':
        return geojson2csv(f, **kwargs)
    elif format == 'csv':
        return csv2csv(f, **kwargs)
    elif format == 'dbf':
        if six.PY3:
            raise ValueError('format "dbf" is not supported forthis version of Python.')
        return dbf2csv(f, **kwargs)
    else:
        raise ValueError('format "%s" is not supported' % format)
Example #2
0
def convert(f, format, schema=None, key=None, **kwargs):
    """
    Convert a file of a specified format to CSV.
    """
    if not f:
        raise ValueError('f must not be None')

    if not format:
        raise ValueError('format must not be None')

    if format == 'fixed':
        if not schema:
            raise ValueError('schema must not be null when format is "fixed"')

        return fixed2csv(f, schema, **kwargs)
    elif format == 'xls':
        return xls2csv(f, **kwargs)
    elif format == 'xlsx':
        return xlsx2csv(f, **kwargs)
    elif format == 'json':
        return json2csv(f, key, **kwargs)
    elif format == 'ndjson':
        return ndjson2csv(f, **kwargs)
    elif format == 'geojson':
        return geojson2csv(f, **kwargs)
    elif format == 'csv':
        return csv2csv(f, **kwargs)
    elif format == 'dbf':
        if six.PY3:
            raise ValueError(
                'format "dbf" is not supported forthis version of Python.')
        return dbf2csv(f, **kwargs)
    else:
        raise ValueError('format "%s" is not supported' % format)
Example #3
0
 def test_csv_itself(self):
     with open('examples/testfixed_converted.csv', 'r') as f:
         contents = f.read()
         f.seek(0)
         self.assertEqual(contents, csvitself.csv2csv(f))
Example #4
0
 def test_csv_itself(self):
     with open('examples/testfixed_converted.csv', 'r') as f:
         contents = f.read()
         f.seek(0)
         self.assertEqual(contents, csvitself.csv2csv(f))