get-city-code.py: clarifying output

This commit is contained in:
Alarig Le Lay 2020-11-30 12:32:05 +01:00
parent 2b8f378a9d
commit a974495bea
No known key found for this signature in database
GPG Key ID: C865491BF197B54F
1 changed files with 9 additions and 11 deletions

View File

@ -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 isnt taken in be shown, all the MATCHES are displayed otherwise. The font case isnt 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,14 +46,7 @@ def csvloop(file):
entries = csv.reader(file) entries = csv.reader(file)
for entry in entries: for entry in entries:
if len(args.country) > 0: csvprocessing(entry)
if args.country.lower() == entry[1].lower():
csvprocessing(entry)
else:
pass
else:
csvprocessing(entry)
def print_results(exactitude, result_list): def print_results(exactitude, result_list):
"""Stupid function to print results based on very basic formating """Stupid function to print results based on very basic formating
@ -88,7 +82,11 @@ if len(EXACT_MATCH) > 0:
print_results('Exact match', EXACT_MATCH) print_results('Exact match', EXACT_MATCH)
# If the country hasnt been provided but the cit(y|es) exist(s) # If the country hasnt 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)