scraper/code_gov/__init__.py
def force_attributes(metadata, config):
    """
    Forces certain fields in the Code.gov Metadata json
    """

    organization = config.get('organization', '')
    logger.debug('Organization: %s', organization)

    contact_email = config.get('contact_email')
    logger.debug('Contact Email: %s', contact_email)

    permissions = config.get('permissions', {})
    default_usage = permissions.get('usageType', '')
    default_exemption_text = permissions.get('exemptionText', '')
    logger.debug('Default usageType: %s', default_usage)
    logger.debug('Default exemptionText: %s', default_exemption_text)

    # Force certain fields
    if organization:
        logger.debug('Forcing Organization to: %s', organization)

    if contact_email:
        logger.debug('Forcing Contact Email to: %s', contact_email)

    for release in metadata['releases']:
        if organization:
            release['organization'] = organization

        if contact_email:
            release['contact']['email'] = contact_email

        if 'licenses' not in release['permissions']:
            release['permissions']['licenses'] = None

        if 'description' not in release:
            release['description'] = 'No description available...'

        if 'usageType' not in release['permissions']:
            release['permissions']['usageType'] = default_usage
            release['permissions']['exemptionText'] = default_exemption_text

    return metadata
def force_attributes(metadata, config):
    """
    Forces certain fields in the Code.gov Metadata json
    """

    organization = config.get('organization', '')
    logger.debug('Organization: %s', organization)

    contact_email = config.get('contact_email')
    logger.debug('Contact Email: %s', contact_email)

    permissions = config.get('permissions', {})
    default_usage = permissions.get('usageType', '')
    default_exemption_text = permissions.get('exemptionText', '')
    logger.debug('Default usageType: %s', default_usage)
    logger.debug('Default exemptionText: %s', default_exemption_text)

    # Force certain fields
    if organization:
        logger.debug('Forcing Organization to: %s', organization)

    if contact_email:
        logger.debug('Forcing Contact Email to: %s', contact_email)

    for release in metadata['releases']:
        if organization:
            release['organization'] = organization

        if contact_email:
            release['contact']['email'] = contact_email

        if 'licenses' not in release['permissions']:
            release['permissions']['licenses'] = None

        if 'description' not in release:
            release['description'] = 'No description available...'

        if 'usageType' not in release['permissions']:
            release['permissions']['usageType'] = default_usage
            release['permissions']['exemptionText'] = default_exemption_text

    return metadata
Forces certain fields in the Code.gov Metadata json