Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 50 lines (42 sloc) 1.71 KB
#!/usr/bin/env python
import json # 2.6 and above
except ImportError:
import simplejson as json # 2.5 and below
import httplib, re, logging
def get_dests(logger=None):
if logger is None:
logger = logging.getLogger('RyanairDest')
conn = httplib.HTTPConnection('')
logger.debug("Sending request for destinations array")
conn.request("GET", '/en/booking/form')
resp = conn.getresponse()"Request success, response code: %d" % resp.status)
if (resp.status != 200):
raise RyanairException("Invalid return status from Ryanair. \
Expected: 200, got: %d" % resp.status)
html =
airport_part ='var Dests=.*\s*([\S\s]*?);', html)
if airport_part is None:
raise RyanairException("Parsing of ryanair airports changed.")
airport_arr = re.split(",\n","%d airports found" % int(len(airport_arr)/2))
airport_dirs, airport_names = {}, {}
for it in airport_arr:
# Example: sKUN='Kaunas'
if it[0] == 's':
airport_names[it[1:4]] = it[6:-1]
# Example line: aKUN=aKUN=['STN','BGY','RYG','BVA','TMP']
short, dirs = it[1:4], it[5:]
# Expand dirs (this looks like json array, but improper)
airport_dirs[short] = json.loads(dirs.replace("'", '"'))
return airport_names, airport_dirs
if __name__ == "__main__":
logger = logging.getLogger('RyanairDest')
names, dests = get_dests(logger)
for k, v in dests.iteritems():
for dest in v:
print ("%s-%s" % (k, dest) )