#!/usr/bin/env python import string import sys import sets null_trans = string.maketrans('', '') remove_chars = ". '" #sys.exit(1) counties_file = open('../raw_data/Census/app_a02.txt', 'r') counties_file.readline() counties_file.readline() counties_all = sets.Set() states_con = ['AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DE', 'FL', 'GA', 'IA', 'ID', 'IL', 'IN', 'KS', 'KY', 'LA', 'MA', 'MD', 'ME', 'MI', 'MN', 'MO', 'MS', 'MT', 'NC', 'ND', 'NE', 'NH', 'NJ', 'NM', 'NV', 'NY', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VA', 'VT', 'WA', 'WI', 'WV', 'WY'] states_con.sort() print states_con print len(states_con) states_all = sets.Set() pretty_name = {} while 1: line = counties_file.readline() if not line or len(line) < 2: break if line[-2] == '-': line = line[:-1] + counties_file.readline()[10:] (f1, f2, county, state) = string.split(line[:-1], ' ') pretty = county if state == ' AK': print line if state == 'DC': state = 'VA' if county == 'District of Columbia': continue if county == 'Miami-Dade': county = 'Dade' if not state in states_con: continue county = string.lower(string.translate(county, null_trans, ". '")) state = string.lower(state) pretty_name[county] = pretty counties_all.add((county, state)) states_all.add(state) print len(counties_all) counties_airports = sets.Set() airports_file = open('../raw_data/FAA_ATA-100/APT.del', 'r') for line in airports_file.readlines(): fields = string.split(line, '|') if not fields[0] == 'APT': continue landing_facility = fields[2] identifier = fields[3] county = fields[9] state_abbrev = fields[10] usage = fields[13] if not usage == 'PU': continue county = string.translate(county, null_trans, ". '") if state_abbrev not in states_con: continue #if not county == 'TIPPECANOE': # continue if not landing_facility == 'AIRPORT': continue t = (string.lower(county), string.lower(state_abbrev)) if not t in counties_all: #print t #print line None counties_airports.add(t) print len(counties_all - counties_airports) sys.exit(1) for missing in counties_all - counties_airports: (county, state) = missing print string.upper(state), pretty_name[county]