Created
September 8, 2022 13:18
-
-
Save adimiti/01b68935f806d251cdc47ce51c714dbd to your computer and use it in GitHub Desktop.
A call sign prefix lookup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The source is https://en.wikipedia.org/wiki/ITU_prefix | |
| data = {\ | |
| "A[A-L]": "United States", | |
| "A[M-O]": "Spain", | |
| "A[P-S]": "Pakistan", | |
| "A[T-W]": "India", | |
| "AX": "Australia", | |
| "A[Y-Z]": "Argentina", | |
| "A2": "Botswana", | |
| "A3": "Tonga", | |
| "A4": "Oman", | |
| "A5": "Bhutan", | |
| "A6": "United Arab Emirates", | |
| "A7": "Qatar", | |
| "A8": "Liberia", | |
| "A9": "Bahrain", | |
| "B": "China", | |
| "B[M-QU-X]": "Taiwan", | |
| "C[A-E]": "Chile", | |
| "C[F-K]": "Canada", | |
| "C[L-M]": "Cuba", | |
| "CN": "Morocco", | |
| "CO": "Cuba", | |
| "CP": "Bolivia", | |
| "C[Q-U]": "Portugal", | |
| "C[V-X]": "Uruguay", | |
| "C[Y-Z]": "Canada", | |
| "C2": "Nauru", | |
| "C3": "Andorra", | |
| "C4": "Cyprus", | |
| "C5": "The Gambia", | |
| "C6": "The Bahamas", | |
| "C7": "World Meteorological Organization", | |
| "C[8-9]": "Mozambique", | |
| "D[A-R]": "Germany", | |
| "D[S-T]": "South Korea", | |
| "D[U-Z]": "Philippines", | |
| "D[2-3]": "Angola", | |
| "D4": "Cape Verde", | |
| "D5": "Liberia", | |
| "D6": "Comoros", | |
| "D[7-9]": "South Korea", | |
| "E[A-H]": "Spain", | |
| "E[I-J]": "Ireland", | |
| "EK": "Armenia", | |
| "EL": "Liberia", | |
| "E[M-O]": "Ukraine", | |
| "E[P-Q]": "Iran", | |
| "ER": "Moldova", | |
| "ES": "Estonia", | |
| "ET": "Ethiopia", | |
| "E[U-W]": "Belarus", | |
| "EX": "Kyrgyzstan", | |
| "EY": "Tajikistan", | |
| "EZ": "Turkmenistan", | |
| "E2": "Thailand", | |
| "E3": "Eritrea", | |
| "E4": "Palestinian Authority", | |
| "E5": "Cook Islands", | |
| "E6": "Niue", | |
| "E7": "Bosnia and Herzegovina", | |
| "F": "France (and its Overseas departments/territories)", | |
| "G": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "HA": "Hungary", | |
| "HB": "Switzerland", | |
| "HB (HB0, HB3Y, HBL) ": "Liechtenstein (uses prefixes allocated to Switzerland)", | |
| "H[C-D]": "Ecuador", | |
| "HE": "Switzerland", | |
| "HF": "Poland", | |
| "HG": "Hungary", | |
| "HH": "Haiti", | |
| "HI": "Dominican Republic", | |
| "H[J-K]": "Colombia", | |
| "HL": "South Korea", | |
| "HM": "North Korea", | |
| "HN": "Iraq", | |
| "H[O-P]": "Panama", | |
| "H[Q-R]": "Honduras", | |
| "HS": "Thailand", | |
| "HT": "Nicaragua", | |
| "HU": "El Salvador", | |
| "HV": "Vatican City", | |
| "H[W-Y]": "France (and its Overseas departments/territories)", | |
| "HZ": "Saudi Arabia", | |
| "H2": "Cyprus", | |
| "H3": "Panama", | |
| "H4": "Solomon Islands", | |
| "H[6-7]": "Nicaragua", | |
| "H[8-9]": "Panama", | |
| "I": "Italy", | |
| "J[A-S]": "Japan", | |
| "J[T-V]": "Mongolia", | |
| "J[W-X]": "Norway", | |
| "JY": "Jordan", | |
| "JZ": "Indonesia", | |
| "J2": "Djibouti", | |
| "J3": "Grenada", | |
| "J4": "Greece", | |
| "J5": "Guinea-Bissau", | |
| "J6": "Saint Lucia", | |
| "J7": "Dominica", | |
| "J8": "Saint Vincent and the Grenadines", | |
| "K": "United States", | |
| "L[A-N]": "Norway", | |
| "L[O-W]": "Argentina", | |
| "LX": "Luxembourg", | |
| "LY": "Lithuania", | |
| "LZ": "Bulgaria", | |
| "L[2-9]": "Argentina", | |
| "M": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "N": "United States", | |
| "O[A-C]": "Peru", | |
| "OD": "Lebanon", | |
| "OE": "Austria", | |
| "O[F-J]": "Finland", | |
| "O[K-L]": "Czech Republic", | |
| "OM": "Slovakia", | |
| "O[N-T]": "Belgium", | |
| "O[U-Z]": "Denmark", | |
| "P[A-I]": "Netherlands", | |
| "PJ": "Netherlands - Former Netherlands Antilles", | |
| "P[K-O]": "Indonesia", | |
| "P[P-Y]": "Brazil", | |
| "PZ": "Suriname", | |
| "P2": "Papua New Guinea", | |
| "P3": "Cyprus", | |
| "P4": "Aruba", | |
| "P[5-9]": "North Korea", | |
| "R": "Russia", | |
| "S[A-M]": "Sweden", | |
| "S[N-R]": "Poland", | |
| "SS[A-M]": "Egypt", | |
| "SS[N-Z]|ST[A-Z]": "Sudan", | |
| "SU": "Egypt", | |
| "S[V-Z]": "Greece", | |
| "S[2-3]": "Bangladesh", | |
| "S5": "Slovenia", | |
| "S6": "Singapore", | |
| "S7": "Seychelles", | |
| "S8": "South Africa", | |
| "S9": "Sao Tome and Principe", | |
| "T[A-C]": "Turkey", | |
| "TD": "Guatemala", | |
| "TE": "Costa Rica", | |
| "TF": "Iceland", | |
| "TG": "Guatemala", | |
| "TH": "France (and its Overseas departments/territories)", | |
| "TI": "Costa Rica", | |
| "TJ": "Cameroon", | |
| "TK": "France (and its Overseas departments/territories)", | |
| "TL": "Central African Republic", | |
| "TM": "France (and its Overseas departments/territories)", | |
| "TN": "Republic of the Congo", | |
| "T[O-Q]": "France (and its Overseas departments/territories)", | |
| "TR": "Gabon", | |
| "TS": "Tunisia", | |
| "TT": "Chad", | |
| "TU": "Ivory Coast", | |
| "T[V-X]": "France (and its Overseas departments/territories)", | |
| "TY": "Benin", | |
| "TZ": "Mali", | |
| "T2": "Tuvalu", | |
| "T3": "Kiribati", | |
| "T4": "Cuba", | |
| "T5": "Somalia", | |
| "T6": "Afghanistan", | |
| "T7": "San Marino", | |
| "T8": "Palau", | |
| "U[A-I]": "Russia", | |
| "U[J-M]": "Uzbekistan", | |
| "U[N-Q]": "Kazakhstan", | |
| "U[R-Z]": "Ukraine", | |
| "V[A-G]": "Canada", | |
| "V[H-N]": "Australia", | |
| "VO": "Canada (formerly Dominion of Newfoundland)", | |
| "V[P-Q]": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "VR": "Hong Kong (Special administrative regions of China)", | |
| "VS": "United Kingdom", | |
| "V[T-W]": "India", | |
| "V[X-Y]": "Canada", | |
| "VZ": "Australia", | |
| "V2": "Antigua and Barbuda", | |
| "V3": "Belize", | |
| "V4": "Saint Kitts and Nevis", | |
| "V5": "Namibia", | |
| "V6": "Federated States of Micronesia", | |
| "V7": "Marshall Islands", | |
| "V8": "Brunei", | |
| "W": "United States", | |
| "X[A-I]": "Mexico", | |
| "X[J-O]": "Canada", | |
| "XP": "Denmark", | |
| "X[Q-R]": "Chile", | |
| "XS": "China", | |
| "XT": "Burkina Faso", | |
| "XU": "Cambodia", | |
| "XV": "Vietnam", | |
| "XW": "Laos", | |
| "XX": "Macao (Special administrative regions of China)", | |
| "X[Y-Z]": "Burma", | |
| "YA": "Afghanistan", | |
| "Y[B-H]": "Indonesia", | |
| "YI": "Iraq", | |
| "YJ": "Vanuatu", | |
| "YK": "Syria", | |
| "YL": "Latvia", | |
| "YM": "Turkey", | |
| "YN": "Nicaragua", | |
| "Y[O-R]": "Romania", | |
| "YS": "El Salvador", | |
| "Y[T-U]": "Serbia", | |
| "Y[V-Y]": "Venezuela", | |
| "Y[2-9]": "Germany", | |
| "ZA": "Albania", | |
| "Z[B-J]": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "Z[K-M]": "New Zealand", | |
| "Z[N-O]": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "ZP": "Paraguay", | |
| "ZQ": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "Z[R-U]": "South Africa", | |
| "Z[V-Z]": "Brazil", | |
| "Z2": "Zimbabwe", | |
| "Z3": "North Macedonia", | |
| "Z8": "South Sudan", | |
| "2": "United Kingdom (and its overseas territories/Crown dependencies)", | |
| "3A": "Monaco", | |
| "3B": "Mauritius", | |
| "3C": "Equatorial Guinea", | |
| "3DA-3DM": "Eswatini", | |
| "3DN-3DZ": "Fiji", | |
| "3[E-F]": "Panama", | |
| "3G": "Chile", | |
| "3[H-U]": "China", | |
| "3V": "Tunisia", | |
| "3W": "Vietnam", | |
| "3X": "Guinea", | |
| "3Y": "Norway", | |
| "3Z": "Poland", | |
| "4[A-C]": "Mexico", | |
| "4[D-I]": "Philippines", | |
| "4[J-K]": "Azerbaijan", | |
| "4L": "Georgia", | |
| "4M": "Venezuela", | |
| "4O": "Montenegro", | |
| "4[P-S]": "Sri Lanka", | |
| "4T": "Peru", | |
| "4U": "United Nations", | |
| "4V": "Haiti", | |
| "4W": "Timor-Leste", | |
| "4X": "Israel", | |
| "4Y": "International Civil Aviation Organization", | |
| "4Z": "Israel", | |
| "5A": "Libya", | |
| "5B": "Cyprus", | |
| "5[C-G]": "Morocco", | |
| "5[H-I]": "Tanzania", | |
| "5[J-K]": "Colombia", | |
| "5[L-M]": "Liberia", | |
| "5[N-O]": "Nigeria", | |
| "5[P-Q]": "Denmark", | |
| "5[R-S]": "Madagascar", | |
| "5T": "Mauritania", | |
| "5U": "Niger", | |
| "5V": "Togo", | |
| "5W": "Western Samoa", | |
| "5X": "Uganda", | |
| "5[Y-Z]": "Kenya", | |
| "6[A-B]": "Egypt", | |
| "6C": "Syria", | |
| "6[D-J]": "Mexico", | |
| "6[K-N]": "South Korea", | |
| "6O": "Somalia", | |
| "6[P-S]": "Pakistan", | |
| "6[T-U]": "Sudan", | |
| "6[V-W]": "Senegal", | |
| "6X": "Madagascar", | |
| "6Y": "Jamaica", | |
| "6Z": "Liberia", | |
| "7[A-I]": "Indonesia", | |
| "7[J-N]": "Japan", | |
| "7O": "Yemen", | |
| "7P": "Lesotho", | |
| "7Q": "Malawi", | |
| "7R": "Algeria", | |
| "7S": "Sweden", | |
| "7[T-Y]": "Algeria", | |
| "7Z": "Saudi Arabia", | |
| "8[A-I]": "Indonesia", | |
| "8[J-N]": "Japan", | |
| "8O": "Botswana", | |
| "8P": "Barbados", | |
| "8Q": "Maldives", | |
| "8R": "Guyana", | |
| "8S": "Sweden", | |
| "8[T-Y]": "India", | |
| "8Z": "Saudi Arabia", | |
| "9A": "Croatia", | |
| "9[B-D]": "Iran", | |
| "9[E-F]": "Ethiopia", | |
| "9G": "Ghana", | |
| "9H": "Malta", | |
| "9[I-J]": "Zambia", | |
| "9K": "Kuwait", | |
| "9L": "Sierra Leone", | |
| "9M": "Malaysia", | |
| "9N": "Nepal", | |
| "9[O-T]": "Democratic Republic of the Congo", | |
| "9U": "Burundi", | |
| "9V": "Singapore", | |
| "9W": "Malaysia", | |
| "9X": "Rwanda", | |
| "9[Y-Z]": "Trinidad and Tobago", | |
| } | |
| import re | |
| # start with exceptions: | |
| seq = [k for k,_ in data.items()] | |
| seq.sort(key=(lambda x: len(x)),reverse=1) | |
| # precompile the regex in advance | |
| rec = [(re.compile(i), data[i]) for i in seq] | |
| # some tests | |
| test = "4X4YQ OD5TM EK2JL PY7REW 4L1VU 9K2FR BBBBB BU3XX BQ2AA".split() | |
| # perform the test | |
| for i in test: | |
| print(f'{i}', end=' ', flush=True) | |
| for r,c in rec: | |
| p = r.match(i) | |
| if p: | |
| print(c) | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment