Python script to search flights using Goibibo API | Daily Python #25
Published in
2 min readFeb 10, 2020
This article is a tutorial on how to search for flights by consuming the Goibibo API in Python.
Requirements:
- Python 3.0
- Pip
Install the following packages:
- requests — Library to making HTTP requests.
- pprint — PrettyPrinter:
pip install requests pprint
First, let’s sign up on the Goibibo’s API portal
Fill in the details and activate your account from the email received. You will now be able to access the API key and the Application ID, which will be used for making calls with the APIs.
First, let’s import the requests module
import requests
from pprint import PrettyPrinter
pp = PrettyPrinter()
Store the App ID and the API Key into variables for future use
AppID = "YOUR_GOIBIBO_APP_ID"
AppKey = "YOUR_GOIBIBO_APP_KEY"
The parameters required for fetching flights using the API
Let’s create a dictionary to store the values of these parameters
params = {
"app_id":AppID,
"app_key":AppKey,
"format":"json",
"source":"PNQ",
"destination":"BOM",
"dateofdeparture":"20200215",
"dateofarrival":"",
"":"",
"seatingclass":"E",
"adults":"1",
"children":"0",
"counter":"100",
}
Let’s hit the API Url and fetch the result for the above parameters
URL = "http://developer.goibibo.com/api/search/"response = requests.get(URL,params=params).json()
pp.pprint(response)
We can loop this code and try to find the best flight price for the given locations and then simply send an email reminder using the mail service which was discussed in Daily Python #1.
I hope this article was helpful, do leave some claps if you liked it.