def prepare_resource(self, resource):
     resource['encoding'] = 'utf-8'
     basename, _ = os.path.splitext(get_path(resource))
     resource['path'] = basename + '.csv'
     resource['format'] = 'csv'
     resource['dialect'] = dict(lineTerminator='\r\n',
                                delimiter=',',
                                doubleQuote=True,
                                quoteChar='"',
                                skipInitialSpace=False)
     super(CSVFormat, self).prepare_resource(resource)
Beispiel #2
0
resources = ResourceMatcher(parameters.get('resources'), datapackage)
ignore_missing = parameters.get('ignore-missing', False)
limit_rows = parameters.get('limit-rows', -1)

new_resource_iterator = []
for resource in datapackage['resources']:

    if streamable(resource):
        url = resource[PROP_STREAMED_FROM]

        name = resource['name']
        if not resources.match(name):
            continue

        path = get_path(resource)
        if path is None or path == PATH_PLACEHOLDER:
            path = os.path.join('data', name + '.csv')
            resource['path'] = path

        resource[PROP_STREAMING] = True

        rows = stream_reader(resource, url, ignore_missing or url == "",
                             limit_rows, resource.pop('http_headers', None))

        new_resource_iterator.append(rows)

    elif streaming(resource):
        new_resource_iterator.append(next(resource_iterator))

spew(datapackage, new_resource_iterator)
 def prepare_resource(self, resource):
     resource['encoding'] = 'utf-8'
     basename, _ = os.path.splitext(get_path(resource))
     resource['path'] = basename + '.json'
     resource['format'] = 'json'
     super(JSONFormat, self).prepare_resource(resource)