This site isn’t all about reviews but its also about how you can optimize your travels. Searching for rewards can be time consuming. You want to maximize your points by understanding where you can go, where you can stop over at, pick better airlines, etc. What if you could easily search for flights with ease and then determine how you are going to travel? Aeroplan’s/Air Canada’s availability calendar is weak and sometimes misleading. Today I am going to show you how you can search flights using simply python to get those business (or better) class seats on Air Canada, Singapore, EVA, etc. This hack is for Aeroplan/Air Canada rewards but the approach could be applied to any reward system. This is the process I used to book my latest trip. Essentially all we are doing here is:
- Logging into the Aeroplan Reward Site
- Searching for the Flight
- Retrieving the results in JSON
First you need to login. So what you do is post your username and password to Aeroplan and save your session.
[code lang=”python”]
def getFlights(O, D, DD, C, P):
URL_LOGIN = ‘https://www.aeroplan.com/login/authProcess.do’
URL_FLIGHT = ‘https://www.aeroplan.com/adr/SearchProcess.do’
login_data = { ‘cust’ : USERNAME, ‘pin’ : PASSWORD}
s = requests.Session()
s.post(URL_LOGIN, login_data)
[/code]
The next is to structure your data and pass that into your search. I only search one-ways as I was trying to build a multi-city destination that included two stop overs. In this example
- O=Origin (IAH),
- D=Destination (SIN),
- DD=Date of Travel (2018-08-15),
- P=Number of Passengers (2),
- C=Cabin Class (Business)
[code lang=”python”]
flight_data = {‘currentTripTab’ : ‘oneway’,
‘modifySearch’ : ‘false’,
‘city1FromOneway’ : O,
‘city1FromOnewayCode’ : O,
‘city1ToOneway’ : D,
‘city1ToOnewayCode’ : D,
‘l1Oneway’ : DD,
‘l1OnewayDate’ : DD,
‘OnewayAdultsNb’ : P,
‘OnewayTotalPassengerNb’ : P,
‘OnewayCabin’ : C
}
[/code]
Once you have created your data structure, it is now time to post that data to the search URL and retrieve the results in a JSON object.
*Please note that the “forceIkk” was searching for premium rewards as I was Super Elite. For some of you, you should change this to false otherwise it will show results that are double the points.
[code lang=”python”]
s.post(URL_FLIGHT, flight_data)
s.get(‘https://www.aeroplan.com/adr/Results.do’)
f3 = s.post(‘https://www.aeroplan.com/adr/Results_Ajax.jsp?searchType=oneway&forceIkk=true’) s.get(‘https://www.aeroplan.com/log_out.do’)
try: json_obj = json.loads(f3.text)
return json_obj
except: json_obj = {}
return json_obj
[/code]
Once you have the JSON object, you can then proceed to parse that data. The results will actually provide you all cabin classes even though you specify Business, Economy, etc. Once you have this data you can insert this into a mysql database and view what availability, flights, etc. there are. You can also put this in a wrapper that searches as many dates as you want so that you can see when flights leave, what is available, etc. over a large time frame.