harvester_odt/comunweb/converter.py
def _comunweb_dataset_to_ckan(self, obj):
        """
        Prepare an object from comunweb for insertion to ckan
        """

        metadata = obj['full_metadata']
        values = comunweb_normalize_field_values(metadata)

        # License is available in:
        # metadata['fields']['licenza']['value']['link']
        # Downloading that URL gets to a json file; license id is in:
        # data['fields']['titolo']['value']
        license_url = metadata['fields']['licenza']['value']['link']
        license_id = self._get_cached_license(license_url)

        dataset = {
            'name': slugify(obj['objectName']),
            'title': obj['objectName'].strip(),
            'notes': '',
            'author': '',
            'author_email': '',
            'maintainer': '',
            'maintainer_email': '',
            'url': '',
            'license_id': license_id,
            'owner_org': self.conf['org_name'],
            'groups': [],  # todo: set this?
            'extras': {},
            'tags': [],
            'resources': [],
        }

        # Set dataset extras
        for key, val in values.iteritems():
            if val['value'] is not None:
                if isinstance(val['value'], datetime.datetime):
                    val['value'] = val['value'].strftime(DATE_FORMAT)
                dataset['extras'][val['label']] = val['value']

        # Update fields by reading from extras
        # ----------------------------------------

        try:
            dataset['notes'] = unicode(values['abstract']['value'] or '')
        except KeyError:
            pass

        try:
            dataset['notes'] += u'\n\n' + unicode(values['descrizione']['value'] or '')  # noqa
        except KeyError:
            pass

        extras = dataset['extras']

        try:
            extras['Copertura Temporale (Data di inizio)'] = \
                values['data_iniziovalidita']['value']
        except KeyError:
            pass

        try:
            extras['Copertura Temporale (Data di fine)'] = \
                values['data_fine_validita']['value']
        except KeyError:
            pass

        try:
            extras['Aggiornamento'] = \
                metadata['frequenza_aggiornamento']['value']['objectName']
        except KeyError:
            pass

        try:
            extras['Codifica Caratteri'] = extras.pop('Codifica caratteri')
        except KeyError:
            pass

        # Create resources
        # ----------------------------------------

        dataset['resources'] = list(self._resources_from_metadata(metadata))
        self._fix_resource_format_case(dataset['resources'])

        return dataset

        Prepare an object from comunweb for insertion to ckan
        
Prepare an object from comunweb for insertion to ckan
Prepare an object from comunweb for insertion to ckan
def _comunweb_dataset_to_ckan(self, obj):
        metadata = obj['full_metadata']
        values = comunweb_normalize_field_values(metadata)
        license_url = metadata['fields']['licenza']['value']['link']
        license_id = self._get_cached_license(license_url)
        dataset = {
            'name': slugify(obj['objectName']),
            'title': obj['objectName'].strip(),
            'notes': '',
            'author': '',
            'author_email': '',
            'maintainer': '',
            'maintainer_email': '',
            'url': '',
            'license_id': license_id,
            'owner_org': self.conf['org_name'],
            'groups': [],  
            'extras': {},
            'tags': [],
            'resources': [],
        }
        for key, val in values.iteritems():
            if val['value'] is not None:
                if isinstance(val['value'], datetime.datetime):
                    val['value'] = val['value'].strftime(DATE_FORMAT)
                dataset['extras'][val['label']] = val['value']
        try:
            dataset['notes'] = unicode(values['abstract']['value'] or '')
        except KeyError:
            pass
        try:
            dataset['notes'] += u'\n\n' + unicode(values['descrizione']['value'] or '')  
        except KeyError:
            pass
        extras = dataset['extras']
        try:
            extras['Copertura Temporale (Data di inizio)'] = \
                values['data_iniziovalidita']['value']
        except KeyError:
            pass
        try:
            extras['Copertura Temporale (Data di fine)'] = \
                values['data_fine_validita']['value']
        except KeyError:
            pass
        try:
            extras['Aggiornamento'] = \
                metadata['frequenza_aggiornamento']['value']['objectName']
        except KeyError:
            pass
        try:
            extras['Codifica Caratteri'] = extras.pop('Codifica caratteri')
        except KeyError:
            pass
        dataset['resources'] = list(self._resources_from_metadata(metadata))
        self._fix_resource_format_case(dataset['resources'])
        return dataset
def _comunweb_dataset_to_ckan ( self , obj ) : metadata = obj [ 'full_metadata' ] values = comunweb_normalize_field_values ( metadata ) license_url = metadata [ 'fields' ] [ 'licenza' ] [ 'value' ] [ 'link' ] license_id = self . _get_cached_license ( license_url ) dataset = { 'name' : slugify ( obj [ 'objectName' ] ) , 'title' : obj [ 'objectName' ] . strip ( ) , 'notes' : '' , 'author' : '' , 'author_email' : '' , 'maintainer' : '' , 'maintainer_email' : '' , 'url' : '' , 'license_id' : license_id , 'owner_org' : self . conf [ 'org_name' ] , 'groups' : [ ] , 'extras' : { } , 'tags' : [ ] , 'resources' : [ ] , } for key , val in values . iteritems ( ) : if val [ 'value' ] is not None : if isinstance ( val [ 'value' ] , datetime . datetime ) : val [ 'value' ] = val [ 'value' ] . strftime ( DATE_FORMAT ) dataset [ 'extras' ] [ val [ 'label' ] ] = val [ 'value' ] try : dataset [ 'notes' ] = unicode ( values [ 'abstract' ] [ 'value' ] or '' ) except KeyError : pass try : dataset [ 'notes' ] += u'\n\n' + unicode ( values [ 'descrizione' ] [ 'value' ] or '' ) except KeyError : pass extras = dataset [ 'extras' ] try : extras [ 'Copertura Temporale (Data di inizio)' ] = values [ 'data_iniziovalidita' ] [ 'value' ] except KeyError : pass try : extras [ 'Copertura Temporale (Data di fine)' ] = values [ 'data_fine_validita' ] [ 'value' ] except KeyError : pass try : extras [ 'Aggiornamento' ] = metadata [ 'frequenza_aggiornamento' ] [ 'value' ] [ 'objectName' ] except KeyError : pass try : extras [ 'Codifica Caratteri' ] = extras . pop ( 'Codifica caratteri' ) except KeyError : pass dataset [ 'resources' ] = list ( self . _resources_from_metadata ( metadata ) ) self . _fix_resource_format_case ( dataset [ 'resources' ] ) return dataset
Prepare an object from comunweb for insertion to ckan
Prepare an object from comunweb for insertion to ckan
"""
        Prepare an object from comunweb for insertion to ckan
        """ # License is available in: # metadata['fields']['licenza']['value']['link'] # Downloading that URL gets to a json file; license id is in: # data['fields']['titolo']['value'] # todo: set this? # Set dataset extras # Update fields by reading from extras # ---------------------------------------- # noqa # Create resources # ----------------------------------------
self
obj