get-city-code.py: clarifying output
This commit is contained in:
parent
2b8f378a9d
commit
a974495bea
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import csv
|
import csv
|
||||||
|
@ -16,7 +17,7 @@ import sys
|
||||||
parser = argparse.ArgumentParser(description='''Find cities code from UNLOCODE.
|
parser = argparse.ArgumentParser(description='''Find cities code from UNLOCODE.
|
||||||
If the exact name is found when a country code is given, only this match will
|
If the exact name is found when a country code is given, only this match will
|
||||||
be shown, all the MATCHES are displayed otherwise. The font case isn’t taken in
|
be shown, all the MATCHES are displayed otherwise. The font case isn’t taken in
|
||||||
%s/EXACT_MATCH/EXACT_MATCH/account but the accents are. ''')
|
account but the accents are.''')
|
||||||
parser.add_argument('--city', dest='city', type=str, required=True,
|
parser.add_argument('--city', dest='city', type=str, required=True,
|
||||||
help='City name, will be looked for inside the CSV files')
|
help='City name, will be looked for inside the CSV files')
|
||||||
parser.add_argument('--country', dest='country', type=str, required=False,
|
parser.add_argument('--country', dest='country', type=str, required=False,
|
||||||
|
@ -45,13 +46,6 @@ def csvloop(file):
|
||||||
|
|
||||||
entries = csv.reader(file)
|
entries = csv.reader(file)
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
if len(args.country) > 0:
|
|
||||||
if args.country.lower() == entry[1].lower():
|
|
||||||
csvprocessing(entry)
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
|
||||||
csvprocessing(entry)
|
csvprocessing(entry)
|
||||||
|
|
||||||
def print_results(exactitude, result_list):
|
def print_results(exactitude, result_list):
|
||||||
|
@ -88,7 +82,11 @@ if len(EXACT_MATCH) > 0:
|
||||||
print_results('Exact match', EXACT_MATCH)
|
print_results('Exact match', EXACT_MATCH)
|
||||||
# If the country hasn’t been provided but the cit(y|es) exist(s)
|
# If the country hasn’t been provided but the cit(y|es) exist(s)
|
||||||
elif len(MULTIPLE_MATCHES) > 0:
|
elif len(MULTIPLE_MATCHES) > 0:
|
||||||
print_results('Multiple MATCHES', MULTIPLE_MATCHES)
|
print_results('Multiple matches', MULTIPLE_MATCHES)
|
||||||
# Otherwise, throw some garbage to the user
|
# Otherwise, throw some garbage to the user
|
||||||
else:
|
else:
|
||||||
print_results('Non-exact MATCHES', MATCHES)
|
if len(args.country) > 0:
|
||||||
|
print('Country code has been provided, but no match has been found.',
|
||||||
|
file=sys.stderr)
|
||||||
|
print('Falling back to worldwide lookup.', file=sys.stderr)
|
||||||
|
print_results('Non-exact matches', MATCHES)
|
||||||
|
|
Loading…
Reference in a new issue