以下是一个使用Python的示例代码,用于通过阿玛迪斯航班优惠搜索API获取航班优惠信息。
import requests
def search_flight_discounts(origin, destination, departure_date):
url = "https://api.amadeus.com/v1/shopping/flight-offers-discounts"
params = {
"originLocationCode": origin,
"destinationLocationCode": destination,
"departureDate": departure_date,
"currencyCode": "USD",
"adults": 1,
"nonStop": "true",
"max": 10,
}
headers = {
"Authorization": "Bearer YOUR_AMADEUS_API_KEY"
}
response = requests.get(url, params=params, headers=headers)
if response.status_code == 200:
results = response.json()
for offer in results["data"]:
print("航空公司:", offer["offerItems"][0]["services"][0]["segments"][0]["flightSegment"]["carrierCode"])
print("航班号:", offer["offerItems"][0]["services"][0]["segments"][0]["flightSegment"]["number"])
print("出发时间:", offer["offerItems"][0]["services"][0]["segments"][0]["flightSegment"]["departure"]["at"])
print("到达时间:", offer["offerItems"][0]["services"][0]["segments"][0]["flightSegment"]["arrival"]["at"])
print("优惠价格:", offer["offerItems"][0]["price"]["total"])
print("----------------------------------------------")
else:
print("API请求失败:", response.status_code)
# 使用示例
search_flight_discounts("HKG", "LON", "2022-12-01")
请注意,上述代码中的YOUR_AMADEUS_API_KEY需要替换为您自己的阿玛迪斯API密钥。此外,您可能需要根据阿玛迪斯API的文档调整请求参数和解析JSON响应的代码。
下一篇:阿玛迪斯汽车可用性