oneWayFlightQuote(self, From, To)

Programming Language: Python 3 (As of Jan 2022)

Description


Travel() must be initialized first before calling oneWayFlightQuote(). However, as of currently, the location that gets initialized in the Travel() function will not be used for the oneWayFlightQuote() parameters. This function connects to Kayak.com in their one way flights sections of the website. The parameters are concatenated with the URL variable that is in the function. Example of URL variable: "https://www.kayak.com/flights/"+ From + "-" + To + ". This currently only gets the one best one way flight for the desire From and To locations.

Parameters


From, To

  Values of these must be a string of a correctly spelled location.

  From, To: string needs to be a city or IATA Code

Calling Example


        
            atlanta.oneWayFlightQuote('CLT','ATL')
        
        
    

Class Code


        
            def oneWayFlightQuote(self, From, To):
              URL = "https://www.kayak.com/flights/"+ From + "-" + To + "/2022-02-22/?sort=bestflight_a"
              headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0'}
              page = requests.get(URL, headers=headers)
              soup = BeautifulSoup(page.content, "html.parser")
              results_price = soup.find('span', class_='price option-text')
              results_description = soup.find("ol",class_="flights")
              time_pair = results_description.find_all('span',class_ = 'time-pair')
              print("One-Way Plane Trip for", From,'to',To)
              print ("Price:",results_price.text.strip())
              times = []
              for time in time_pair:
                times.append(time.text.replace("\n",""))
              print (From,'-',To,"Departure Time:",times[0],"-",times[1])
              print('\n')
        
    

Additional Information


Access to internet is needed to run this function when called.