|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#!/usr/bin/env python |
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
|
|
import argparse |
|
|
|
|
import csv |
|
|
|
@ -16,7 +17,7 @@ import sys
|
|
|
|
|
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 |
|
|
|
|
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, |
|
|
|
|
help='City name, will be looked for inside the CSV files') |
|
|
|
|
parser.add_argument('--country', dest='country', type=str, required=False, |
|
|
|
@ -45,14 +46,7 @@ def csvloop(file):
|
|
|
|
|
|
|
|
|
|
entries = csv.reader(file) |
|
|
|
|
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): |
|
|
|
|
"""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) |
|
|
|
|
# If the country hasn’t been provided but the cit(y|es) exist(s) |
|
|
|
|
elif len(MULTIPLE_MATCHES) > 0: |
|
|
|
|
print_results('Multiple MATCHES', MULTIPLE_MATCHES) |
|
|
|
|
print_results('Multiple matches', MULTIPLE_MATCHES) |
|
|
|
|
# Otherwise, throw some garbage to the user |
|
|
|
|
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) |
|
|
|
|