コード例 #1
0
ファイル: cleanup.py プロジェクト: kurtraschke/aerodb
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)
コード例 #2
0
ファイル: export.py プロジェクト: kurtraschke/aerodb
def export(infile, outfile, type):
    exporters = {'kml': export_kml, 'csv': export_csv}

    with infile:
        aerodromes = Aerodromes(infile)

    exporters[type](aerodromes.aerodromes, outfile)
コード例 #3
0
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)
コード例 #4
0
def test_lookup(infile, code, type=None):
    aerodromes = Aerodromes(infile)

    if type is not None:
        pprint(
            [aerodromes.aerodromes[a] for a in aerodromes.indexes[type][code]])
    else:
        pprint([
            aerodromes.aerodromes[a] for a in chain.from_iterable(
                [index[code] for index in aerodromes.indexes.values()])
        ])
コード例 #5
0
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)
コード例 #6
0
def duplicate_summary(infile):
    aerodromes = Aerodromes(infile)

    for code_type, code_index in aerodromes.indexes.iteritems():
        for k, v in code_index.iteritems():
            if len(v) > 1:
                print "%s code %s is assigned to %i aerodromes:" % (
                    code_type.upper(), k, len(v))
                for aerodrome in v:
                    print aerodromes.aerodromes[aerodrome]['name']
                    print '\t', aerodromes.aerodromes[aerodrome]['airport']
                print
コード例 #7
0
def duplicate_report(infile, outfile):
    aerodromes = Aerodromes(infile)
    duplicates = set()

    for code_index in aerodromes.indexes.values():
        for v in code_index.values():
            if len(v) > 1:
                for aerodrome in v:
                    duplicates.add(aerodrome)

    with outfile:
        cw = UnicodeWriter(outfile)
        fields = ['name', 'icao', 'iata', 'faa', 'lid', 'airport']
        cw.writerow(fields)

        for aerodrome in duplicates:
            cw.writerow(
                [aerodromes.aerodromes[aerodrome].get(f, '') for f in fields])