def getInspirationFlights(current, leaves, price, duration=None): flights = Flights(API_KEY) return flights.inspiration_search(origin=current, departure_date=leaves, duration=duration, max_price=price) # pprint.pprint(getCheapestFlights(current, to, leaves)) # pprint.pprint(resp) # import amadeus # API_KEY = keys['amadeus']['private'] # def getCheapestFlights(from, to, leaves, returns=None): # flight = amadeus.Flights(API_KEY) # return flight.low_fare_search( # origin = from, # destination = to, # departure_date=leaves + "" if returns is None else "--{}".format(returns) # ) # departure_date = "2016-11-25"
def retrieve_destinations(origin, budget_query, departure_date, duration): # Query for flights via Amadeus flights = Flights(AMADEUS_API_KEY) # Find flights from origin origin_iata = flights.auto_complete(term=origin)[0]['value'] r = flights.inspiration_search(origin=origin_iata, departure_date=departure_date, max_price=budget_query, duration=duration) # Cap number of experiences results = r['results'][:NUM_EXPERIENCES] # Map IATA codes from Amadeus API to human-readable places destinations = [] for iata in results: destination = IATA2CITY.get(iata['destination'], None) if destination is not None: # Return a tuple of HRF city, dates, and price of flight destinations.append((destination, origin_iata, iata['destination'], iata['departure_date'], iata['return_date'], float(iata['price']))) return destinations
def GenerateListsFromCity(ciudadElegidaUsuario, primerDiaPosibleSalida, ultimoDiaPosibleSalida, duracion, currencyByUser): # importamos los modulos necesarios de amadeus y le pasamos la pw from amadeus import Flights flights = Flights('fdNSGaHphktgPWytHqHqBVhcQVVs4uVr') from amadeus import Hotels hotels = Hotels('fdNSGaHphktgPWytHqHqBVhcQVVs4uVr') #aseguramos que las fechas van con guiones primerDiaPosibleSalida_Corregido = primerDiaPosibleSalida.replace("/", "-") ultimoDiaPosibleSalida_Corregido = ultimoDiaPosibleSalida.replace("/", "-") #calculo fecha regreso <- de momento no se emplea primerDiaPosibleSalida_datetime = datetime.datetime.strptime( primerDiaPosibleSalida, '%Y-%m-%d') primerDiaPosibleVuelta_datetime = primerDiaPosibleSalida_datetime + datetime.timedelta( days=duracion) primerDiaPosibleVuelta = (str(primerDiaPosibleVuelta_datetime)[:10]) ultimoDiaPosibleSalida_datetime = datetime.datetime.strptime( ultimoDiaPosibleSalida, '%Y-%m-%d') ultimoDiaPosibleVuelta_datetime = ultimoDiaPosibleSalida_datetime + datetime.timedelta( days=duracion) ultimoDiaPosibleVuelta = (str(ultimoDiaPosibleVuelta_datetime)[:10]) #Obtener codigo ciudad salida respCity = flights.auto_complete(term=ciudadElegidaUsuario) print(respCity) codigoCiudadSalida = respCity[0]['value'] print("Buscando vuelos desde", codigoCiudadSalida) # Buscar vuelos flights = Flights('fdNSGaHphktgPWytHqHqBVhcQVVs4uVr') respVuelos = flights.inspiration_search( origin=codigoCiudadSalida, departure_date=primerDiaPosibleSalida_Corregido + "--" + ultimoDiaPosibleSalida_Corregido, duration=6, max_price=200) print(respVuelos) # Generar listas con resultados listadoDestinosNfila = [] listadoDestinosLargo = [] listadoDestinosCodigo = [] listadoDestinosFechaSalida = [] listadoDestinosFechaVuelta = [] listadoDestinosPrecioVuelo = [] listadoDestinosLats = [] listadoDestinosLons = [] listadoDestinosPais = [] listadoDestinosPrecioHoteles = [] #for i in range (len(respVuelos['results'])): # print(RecuperarNumeroFromIataCode(respVuelos['results'][i]['destination']),respVuelos['results'][i]['destination'],respVuelos['results'][i]['price']) for i in range(len(respVuelos['results'])): print(i) posicionEnListas = RecuperarNumeroFromIataCode( respVuelos['results'][i]['destination']) listadoDestinosNfila.append(posicionEnListas) listadoDestinosLargo.append( listaMunicipalityAirports[posicionEnListas]) listadoDestinosCodigo.append(respVuelos['results'][i]['destination']) listadoDestinosFechaSalida.append( respVuelos['results'][i]['departure_date']) listadoDestinosFechaVuelta.append( respVuelos['results'][i]['return_date']) listadoDestinosPrecioVuelo.append(respVuelos['results'][i]['price']) listadoDestinosLats.append(listaLatsAirports[posicionEnListas]) listadoDestinosLons.append(listaLongsAirports[posicionEnListas]) listadoDestinosPais.append(listaCountryAirports[posicionEnListas]) #print("inciando busqueda hotel cerca de",listaLatsAirports[posicionEnListas],",",listaLongsAirports[posicionEnListas] ) respHoteles = hotels.search_circle( check_in=respVuelos['results'][i]['departure_date'], check_out=respVuelos['results'][i]['return_date'], latitude=float(listaLatsAirports[posicionEnListas]), longitude=float(listaLongsAirports[posicionEnListas]), currency=currencyByUser, radius=30) #km from coordenates=km from airport #print(respHoteles) precioMedioHoteles = 0 numeroHotelesConsiderar = min( len(respHoteles['results']), 5) #max number of hotels to consider in mean price if numeroHotelesConsiderar == 0: precioMedioHoteles = 1000 * duracion else: for h in range(numeroHotelesConsiderar): precioDeCadaHotel = respHoteles['results'][h]['total_price'][ 'amount'] # print(precioDeCadaHotel) # print(respHoteles['results'][h]['location']['latitude']) # print(respHoteles['results'][h]['location']['longitude']) precioMedioHoteles = precioMedioHoteles + float( precioDeCadaHotel) precioMedioHoteles = round( precioMedioHoteles / numeroHotelesConsiderar, 2) listadoDestinosPrecioHoteles.append(precioMedioHoteles) return (listadoDestinosNfila, listadoDestinosLargo, listadoDestinosCodigo, listadoDestinosFechaSalida, listadoDestinosFechaVuelta, listadoDestinosPrecioVuelo, listadoDestinosLats, listadoDestinosLons, listadoDestinosPais, listadoDestinosPrecioHoteles)
#for texting from twilio.rest import TwilioRestClient #inits f_api = Flights(FKEY) t_api = TwilioRestClient(TSID, TTOK) USER_DICT = dict() #do everything below when a request is received of when cron job excecutes: #gets flight results results_json = f_api.inspiration_search( origin = self.starting_location, #use self.guest if class departure_date = self.departure_date, #format should be "2015-11-25--2015-11-30" max_price = self.cost, duration = '3--10') #format should be "1--10" #add to dictionary 5 travel results #5 in case prices are not unique and they get overridden as keys x = 0 flights = dict() for resp in results_json.get('results'): if x < 5: flights[resp.get('price')] = [resp.get('destination'), resp.get('departure_date'), resp.get('return_date'), resp.get('airline'), 'airline_name'] x += 1 else: break
import cgi, cgitb import bottle '''origin = form.getvalue('origin') destination = form.getvalue('destination') departure_date = form.getvalue('date')''' max_price = form.getvalue('max_price') print ("content-type:text/html \r\n\r\n") print ('<HTML>') print ('<HEAD>') print ('<TITLE>SAMPLE CGI PROGRAM</TITLE>') print ('</HEAD>') print ('<BODY>') flights=Flights('as954p7KMzRYH5WN6JBAUz3Z04zkGDQH') resp = flights.inspiration_search(origin='origin', destination='destination', departure_date='date', max_price='max_price') print resp print "Hello World %s"%max_price print ('</BODY>') print ('</HTML'>)
#!/usr/bin/env python from amadeus import Flights from constants import * import sys if __name__ == "__main__": if len(API_KEY) == 0: raise Exception( "Obtain an API key from sandbox.amadeus.com and store it in constants.py" ) sys.exit() print "Flight search:" flights = Flights(API_KEY) resp = flights.inspiration_search(origin='BKK', departure_date="2018-03-25--2018-03-30", max_price=200) print resp