Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Mumartayyab/811a806e7bd5a511df9921f51b91494d to your computer and use it in GitHub Desktop.
Save Mumartayyab/811a806e7bd5a511df9921f51b91494d to your computer and use it in GitHub Desktop.
pip install amadeus
#First install amadeus by using "pip install amadeus" then write the following code
#Write the airport code not the full name as input like LHR for Lahore airport
from amadeus import Client, ResponseError
amadeus = Client(
client_id='Your API KEY',
client_secret='YOUR API SECRET'
)
a = input("Enter the Departure Airport code: ")
b = input("Enter the Arrival Airport code: ")
c = input("Enter the date of travel in the format yyyy-mm-dd :")
try:
body = {
"originDestinations": [
{
"id": "1",
"originLocationCode": a,
"destinationLocationCode": b,
"departureDateTime": {
"date": c
}
}
],
"travelers": [
{
"id": "1",
"travelerType": "ADULT"
}
],
"sources": [
"GDS"
]
}
response = amadeus.shopping.availability.flight_availabilities.post(body)
Data = response.data
if Data == None :
print(f"There is no available flight from {a} to {b} on {c}")
else:
print(f"The available flights from {a} to {b} on {c} are given below: ")
for i in range(len(Data)):
print(f"{i+1}) ")
print("The aircraft number: ")
print(Data[i]['segments'][0]['number'])
print("The aircraft code is:")
print(Data[i]['segments'][0]['aircraft']['code'])
except ResponseError as error:
raise error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment