首先需要了解Bargain Finder Max (BFM)的工作原理。BFM是由Sabre航空公司提供的一种机票搜索和预订服务。它通过搜索系统中所有可能的航线来查找最佳价格,但有时会显示不可用的航线。
解决方法之一是添加过滤器,以在搜索结果中排除不可用的航线。以下代码示例使用Sabre REST API来搜索航班并将结果过滤为只显示可用航班:
import requests
HOTELS_API = "https://api.test.sabre.com/v1/lists/supported/shop/themes"
def search_flights(origin, destination, departure_date):
url = 'https://api.test.sabre.com/v2/shop/flights'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + ACCESS_TOKEN
}
payload = {
'originDestinations': [
{
'departureDate': departure_date,
'originLocationCode': origin,
'destinationLocationCode': destination,
'tpaExtensions': {
'intelliSellTransaction': {
'requestType': {
'Name': '50ITINS'
}
}
}
}
],
'travelers': [
{
'id': '1',
'travelerType': 'ADT',
'farePreferences': {
'type': 'ADULT',
'includeAllianceAndAuthorizationPermitted': True,
'pricingSourceType': 'DISTRIBUTION'
}
}
],
'sources': [
'GDS'
],
'searchQualifiers': {
'pocOverride': 'POS1',
'availabilitySource': 'S',
'cabinPref': [
{
'type': 'ALL'
}
],
'maxFlightOffers': 250,
'pricingQualifiers': {
'currency': 'USD',
'validatingAirlineCodes': [
'AA'
],
'ticketingCountryCode': 'US'
}
}
}
# Call the API and get the response
response = requests.post(url, headers=headers, json=payload)
# Filter the results for available flights
available_flights = []
for flight in response.json()['data'][0]['itineraries']:
if flight['fare']['soldOut'] == False:
available_flights.append(flight)
return available_flights
此示例代码可以请求航班搜索,然