def cleanup(infile, outfile=None, dry_run=False): aerodromes = Aerodromes(infile) mark_iata_duplicates(aerodromes) to_delete = [] for key, aerodrome in aerodromes.aerodromes.iteritems(): if not ('icao' in aerodrome or 'iata' in aerodrome or 'lid' in aerodrome or 'faa' in aerodrome): logging.info("%s has no codes" % (aerodrome['name'])) to_delete.append(key) if not dry_run: for key in to_delete: logging.warn("Deleting %s" % (aerodromes.aerodromes[key]['name'])) del aerodromes.aerodromes[key] aerodromes.write(outfile)
def apply_preferences(preferences, infile, outfile, dry_run=False): preferences = Preferences(preferences) aerodromes = Aerodromes(infile) def zap(candidate_aerodromes, choice, field): for aerodrome in candidate_aerodromes: if aerodrome != choice: logging.info("Removing %s from %s" % (field, aerodrome)) if not dry_run: del aerodromes.aerodromes[aerodrome][field] for field, aerodrome_list in aerodromes.indexes.iteritems(): for code, aerodromes_for_code in aerodrome_list.iteritems(): if len(aerodromes_for_code) > 1: pref = preferences.find_preferred(field, code) if pref is not None: zap(aerodromes_for_code, pref, field) if not dry_run: aerodromes.write(outfile)
def apply_preferences(preferences, infile, outfile, dry_run=False): preferences = Preferences(preferences) aerodromes = Aerodromes(infile) def zap(candidate_aerodromes, choice, field): for aerodrome in candidate_aerodromes: if aerodrome != choice: logging.info("Removing %s from %s" % (field, aerodrome)) if not dry_run: del aerodromes.aerodromes[aerodrome][field] for field, aerodrome_list in aerodromes.indexes.iteritems(): for code, aerodromes_for_code in aerodrome_list.iteritems(): if len(aerodromes_for_code) > 1: pref = preferences.find_preferred(field, code) if pref is not None: zap(aerodromes_for_code, pref, field) if not dry_run: aerodromes.write(outfile)