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)
def drg24kccm(): """put existing 024K DRG ccm data in its right place""" county_names = fips.all_names() for county_name in county_names: fips_code = fips.code_for_name(county_name) old_url = '/d/drg/%s.zip' % county_name old_key = old_bucket.get_key(old_url[1:]) new_url = _new_url('drg-024k', 'county', fips_code, county_name + '.zip') _s3_copy(old_url[1:], new_url)