Exemplo n.º 1
0
def _migrate_county_data(old_prefix, new_abbreviation, name_scheme='ccm'):
    old_keys = old_bucket.list(prefix=old_prefix)
    ext = '.zip'

    for old_key in old_keys:
        s = old_key.key
        split = s.split(old_prefix)[1].split(ext)[0].split('_')

        if name_scheme == 'ccm':
            fips_code = '48' + split[-1]
            name = split[-2]
            new_url = _new_url(new_abbreviation, 'county', fips_code, name + ext)
        elif name_scheme == 'boundary':
            fips_code = '48' + split[0]
            name = fips.name_for_code(fips_code)
            if not name:
                print('could not translate url: %s' % old_key.key)
            else:
                new_url = _new_url(new_abbreviation, 'county', fips_code, name.lower() + '_shp'+ ext)
        elif name_scheme == 'tiger':
            fips_code = split[0]
            if len(fips_code) == 3:
                fips_code = '48' + fips_code
            name = fips.name_for_code(fips_code)
            new_url = _new_url(new_abbreviation, 'county', fips_code, name.lower() + ext)
        elif name_scheme == 'urban':
            name = ' '.join(split[:-1])
            urban_type = split[-1]
            fips_code = fips.code_for_name(name)
            abbreviation_with_type = new_abbreviation + '-' + urban_type
            new_url = _new_url(abbreviation_with_type, 'county', fips_code, name.replace(' ', '-').lower() + '_' + urban_type + ext)

        _s3_copy(old_key, new_url)
Exemplo n.º 2
0
def _lookup_area(area_type, code):
    if area_type == 'county':
        return fips.name_for_code(code)
    elif area_type == 'quad' or area_type == 'qquad':
        return dsn.name_for_code(code)
    elif area_type == 'state' and code == 'tx':
        return 'Texas'
    else:
        raise NotImplementedError