def create_datapackage(record, base_path, stderr):
    # TODO: how are we going to handle which resources to
    # leave alone? They're very inconsistent in some instances
    # And I can't imagine anyone wants to download a copy
    # of, for example, the API base endpoint
    resource_formats_to_ignore = ['API', 'api']
    dataset_name = record.get('name', '') if record else ''

    target_dir = '{base_path}/{name}/data'.format(
        base_path=base_path,
        name=dataset_name)

    try:
        os.makedirs(target_dir)
    except Exception as e:
        stderr.write(e.message)

    for resource in record.get('resources', ''):
        if resource.get('name') is not None:
            resource_id = resource['name']
        else:
            resource_id = resource['id']

        resource_filename = os.path.split(resource['url'])[1]

        output = os.path.join(target_dir, resource_filename)

        # Resources can have a free-form address and no internal info, so in those cases
        # we're going to merely save them using the UID. (If they even exist)
        if output.endswith('/'):
            output = os.path.join(output, resource_id)

        resource['path'] = 'data' + output[len(target_dir):]

        try:
            if resource_formats_to_ignore not in resource['format']:
                r = requests.get(resource['url'], stream=True)
                with open(output, 'wb') as f:
                    for chunk in r.iter_content(chunk_size=DL_CHUNK_SIZE):
                        if chunk: # filter out keep-alive new chunks
                            f.write(chunk)
                            f.flush()
        except requests.ConnectionError:
            stderr.write('URL {url} refused connection. The resource will not be downloaded\n'.format(url=resource['url']))
        except requests.exceptions.RequestException as e:
            stderr.write(e.message)
            stderr.write('\n')

    json_output_name = '{base_path}/{dataset_name}/datapackage.json'.format(
        base_path=base_path, dataset_name=dataset_name)
    with open(json_output_name, 'wb') as out:
        out.write(pretty_json(dict(record, version=DATAPACKAGE_VERSION)))
dataset/ETHPy150Open ckan/ckanapi/ckanapi/cli/dump.py/create_datapackage/swapped operands of `not in`