How do I return True or False from a Python Request depending on whether the field has a value or is null

Viewed 29

I have written a script to extract data from a Python requests response. I would like to write a similar Python script but instead of returning the field values, I would like it to return the field name and either True or False depending on whether the field has a value or not.

for data in datasets:
        dataset_url = data['uri']

d = requests.get(dataset_url)

    output = d.json()

    output_dict = {

            'data_providers': [
                {
                    'name': 'NBN Atlas',
                    'url': 'https://registry.nbnatlas.org/datasets',
                    'api_url': 'https://registry.nbnatlas.org/ws/dataResource',
                    'type': 'host'
                },
                {
                    'name': owner_name,
                    'url': owner_url,
                    'api_url': owner_api_url,
                    'type': 'owner'
                }
            ],

            'datasets': [{
                'title': output.get('name'),
                'url': output.get('alaPublicUrl'),
                'summary': output.get('pubDescription'),
                'dataset_type': output.get('resourceType'),
            }],

            'data_licences': [{
                'name': output.get('licenseType'),
                'version': output.get('licenseVersion'),
                'url': None,
                'description': None,
            }],
        }

The aim is to get a JSON output that looks something like this for the first N values:

[
    {

            'data_providers': [
                {
                    'name': true,
                    'url': true,
                    'api_url': true,
                    'type': true
                },
                {
                    'name': true,
                    'url': true,
                    'api_url': true,
                    'type': true
                }
            ],

            'datasets': [{
                'title': true,
                'url': true,
                'summary': true,
                'dataset_type': true,
            }],

            'data_licences': [{
                'name': true,
                'version': true,
                'url': false,
                'description': false,
            }],
        }
]
0 Answers
Related