IATA Country Sorter

IATACountrySorter is a one-time Python tool that I wrote to organize each airport that’s contained in the database flight searching tool by Google, ITA Matrix.

I use this page to search for flights, as I can harness it better than Google flights, which this just draws from. There is one limitation that motivated the use of this software—one cannot search for departures nor arrivals that are in different countries (e.g. flights from either BOS, NYC, WAS, or EWR to either HYD, TYO, or BKK would throw an exception).

So, I wrote the Python script IATACountrySorter. This script takes a text file of comma separated IATA airport codes and an output directory, and breaks out each port code into a separate comma separated file, sorted on the basis of country the airport is in. The files are named based off of the ISO 3166-1 alpha 2 country code.

I found that this was a very succint way to organize all the airport codes, and is done in such a way that a straightforward automation can be written to search the matrix.

Why is it a one-time use script? Because I already got all the airports, that was the final test! The excercise for home that I would leave the reader is to also sort non-airport IATA codes. For example, XXQ is “Keleti pályaudvar” in Budapest, Hungary (pictured below, by me!), because IATA codes are not just for airports (fun fact—you can search for trains and buses on Google Flights too!).

XXQ is the IATA code for the principal train station in Budapest, Hungary
XXQ is the IATA code for the principal train station in Budapest, Hungary

I found that Python was quite interesting to use for this project. Most of my file reading knowledge is taken from C++, so learning how to properly understand the nuances of the file reading system was very interesting. I would rather have written this in C++, but I understand that the dataset was most available in Python. I’m glad that this project exists, because it gave me some practice in using the set ADT, which I used for my world clock also. I also got to understand the nuances of Python, and learning a different language is always a plus.