def getFlights(self): flights = Flights(AMADEUS_KEY) resp = flights.extensive_search( origin='MAD', destination='BCN', departure_date='2017-06-05--2017-06-28') return resp
def query(request): # get params: budget = int(request.POST["budget"]) origin = request.POST["origin"] num_passengers = int(request.POST["num_passengers"]) # calc departure_date - 7 days from now: today = datetime.datetime.now() x_days_after = today + datetime.timedelta(days=NUM_DAYS_FROM_NOW) departure_date = '%s--%s' % (today.strftime(DATE_FORMAT), x_days_after.strftime(DATE_FORMAT)) logger.debug(departure_date) # calc max price: max_price = int(budget / num_passengers) logger.debug(type(max_price)) # query amadeus: flights = Flights(AMADEUS_API_KEY) resp = flights.extensive_search(origin=origin, destination='LAX', departure_date=departure_date, max_price=budget) # TODO: remove flights with less seats then needed - can't return JsonResponse(data=resp, status=200)
def find_flight(orig, dest, event_date, latitude, longitude): amideus_api = app.config['AMADEUS_KEY'] airport_content = urlopen( "https://api.sandbox.amadeus.com/v1.2/airports/nearest-relevant?apikey=" + amideus_api + "&latitude=" + latitude + "&longitude=" + longitude).read() flights = Flights(amideus_api) # Convert to datetime object event_date = datetime.datetime.strptime(event_date, '%Y-%m-%d %H:%M:%S').date() # Decrememnt date to get departures before the event depart_high = event_date - datetime.timedelta(days=1) depart_low = event_date - datetime.timedelta(days=3) # String for range of dates departure_string = str(depart_low) + "--" + str(depart_high) # The request :) resp = flights.extensive_search(origin=orig, destination=dest, departure_date=departure_string, duration='4--7', max_price=3000) # print json.dumps(resp, indent=2, sort_keys=True) # currency = resp['currency'] # Loop through each found flight and print its info ret = [] for flight in resp.get('results', [])[:5]: airline = flight['airline'] departure_date = datetime.datetime.strptime(flight['departure_date'], '%Y-%m-%d') return_date = datetime.datetime.strptime(flight['return_date'], '%Y-%m-%d') price = flight['price'] # Create a URL to find these flights on google url_string = "https://www.google.com/flights/#search;f=%s;t=%s;d=%s;r=%s;a=%s" % ( orig, dest, str(departure_date.date()), str( return_date.date()), airline) ret += [ "For %s you can fly to %s departing on %s and returning on %s" % (price, dest, departure_date.strftime('%b %d, %Y'), return_date.strftime('%b %d, %Y')) ] return ret
def getFlights(request): flights = Flights('Zt0AY8d5B9UA7ERLccCjiGF6l6gpcUoS') if request.method == 'POST': form = FlightForm(request.POST) if form.is_valid(): data = form.cleaned_data resp = flights.extensive_search( origin=data['origin'], destination=data['destination'], #departure_date = '2018-05-15--2018-05-30' departure_date=data['startdate']) #print(resp) #return HttpResponse(resp['results'][0]['price']) return HttpResponse(json.dumps(resp))
def my_form_post(): form = FlightDataForm(request.form) email = form.email.data depart = form.depart.data.upper() dest = form.dest.data.upper() dates = form.dates.data key = 'uc3P6EbsIUyjwIfT9eQLyNdUp4CbWbem' flights = Flights(key) resp = flights.extensive_search(origin=depart, destination=dest, departure_date=dates) print(resp) a = resp['results'][0]['airline'] b = resp['results'][0]['price'] c = resp['results'][1]['airline'] d = resp['results'][1]['price'] e = resp['results'][2]['airline'] f = resp['results'][2]['price'] flight1 = f'{a} flight: {b}\n' flight2 = f'{c} flight: {d}\n' flight3 = f'{e} flight: {f}\n' smtp_server = smtplib.SMTP('smtp.gmail.com', 587) smtp_server.ehlo() smtp_server.starttls() sendemail = '*****@*****.**' apppwd = 'kxgrfartdbtkdubf' smtp_server.login(sendemail, apppwd) #toaddr = '*****@*****.**' #CHANGE TO ACTUAL SENDER msg = "\r\n".join([ "From: [email protected]", "To: [email protected]", "Subject: Your flight offers for the week", f"Your top 3 flights from {resp['origin']} to {resp['results'][3]['destination']}\n", flight1, flight2, flight3, "Thank You, and have a great day!" ]) smtp_server.sendmail(sendemail, email, msg) return ('Congratulations! You have been subscribed to the mailing list.')
:Authors: bejar :Version: :Created on: 23/01/2017 16:24 """ from AgentUtil.APIKeys import AMADEUS_KEY from amadeus import Flights __author__ = 'bejar' flights = Flights(AMADEUS_KEY) # resp = flights.inspiration_search( # origin='BCN', destination='GVA', # departure_date="2017-01-25--2017-02-28") # resp = flights.extensive_search( origin='MAD', destination='BCN', departure_date='2017-02-05--2017-02-28', duration='4--10') print resp