import urllib2, copy ICAO = "EGLL" # ICAO code we're looking for sock = urllib2.urlopen("http://adds.aviationweather.gov/metars/stations.txt") airport_list = sock.read() sock.close() airport_list = airport_list.splitlines() # filter out comments # this is broke and even if it worked there's more efficient ways for line in airport_list: if line.startswith("!"): airport_list.remove(line) # fun time # this does semi work but again, there's more efficient ways for a_index,line in enumerate(airport_list): # loop through each line airport_icao = None # stupid python.... (don't ask) icao_index = None # ^ if len(line.split()) < 10: # 10 is a high guesstimate, it's to strip out the lines like "OMAN US-MIL 08-APR-03" continue for c_index,c in enumerate(line.split()): # loop through each space seperated segment of the line if len(c) == 4 and c.isupper() and c.isalpha(): # check it looks like an ICAO airport_icao = c icao_index = c_index if airport_icao == ICAO: # check it's the ICAO we're looking for print "ICAO: %s -- Name: %s" % (airport_icao, " ".join(airport_list[a_index].split()[0:icao_index])) break # end the first loop now since there's no point going on