Skip to content

Instantly share code, notes, and snippets.

@Genovo
Created October 22, 2017 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Genovo/861a550f69d1aaef0647e354b1b1f1a5 to your computer and use it in GitHub Desktop.
Save Genovo/861a550f69d1aaef0647e354b1b1f1a5 to your computer and use it in GitHub Desktop.
Shortcut for SWA Fare Lookup-hardcoded Airports
#!/usr/bin/python3
#swaSearch.py
#Southwest Air Fare Searcher
#
#
#Default Aiports:
departureAirportCode = "LAX"
arrivalAirportCode = "SJC"
#departureDate=
#Open Southwest Air Website and enter search terms
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import random
random.seed()
browser = webdriver.Firefox()
browser.get('https://www.southwest.com/flight/')
#orgnl = browser.current_window_handle
#print(orgnl)
#check off one-way button
t = random.random()
oneWay = browser.find_element_by_id("oneWay")
time.sleep(t) //TODO test this
oneWay.click()
# Enter Departure and Arrival Airports
depElem = browser.find_element_by_id("originAirport_displayed")
depElem.clear()
depElem.send_keys(str(departureAirportCode))//TODO test this use variable instead of text
depElem.send_keys(Keys.TAB)
arrElem = browser.find_element_by_id("destinationAirport_displayed")
arrElem.clear()
arrElem.send_keys('SJC')#TODO use variable instead of text
arrElem.send_keys(Keys.TAB)
# Enter DepartureDate
DepartureDate = browser.find_element_by_id("outboundDate")
DepartureDate.clear()
DepartureDate.send_keys('11/06/2015')#TODO use variable instead of text
DepartureDate.send_keys(Keys.TAB)
#
# Enter Departure Time range
depTimeRange = Select(browser.find_element_by_id("outboundTimeOfDay"))
depTimeRange.select_by_visible_text("Noon - 6pm")
#
#TODO ArrivalDate
#submit search terms
searchBtn = browser.find_element_by_id("submitButton")
searchBtn.click()
#RESULTS -Redirected to https://www.southwest.com/flight/select-flight.html?displayOnly=&int=
import time
time.sleep(10)
browser.get_screenshot_as_file("swa.png")
#minFare = browser.find_element_by_name("MinAllFaresOmnitureDataPointsOutbound")
#minFare_text = minFare.text
#minFare_attribute_value = minFare.get_attribute('value')
#print minFare
#print 'minFare.text: {0}'.format(minFare_text)
#print 'minFare.get_attribute(\'value\'): {0}'.format(minFare_attribute_value)
minOBfare = browser.find_element_by_id("MinAllFaresOmnitureDataPointsOutbound")
minFare = minOBfare.get_attribute("Value")
print(minFare)
browser.quit()
#save results page as html file, prep for Beautiful Soup
#import pyautogui, time
#pyautogui.hotkey('ctrl', 's')
#pyautogui.typewrite('/home/bcm/Developer/PythonScripts/swa11-6results')
#pyautogui.click()
#pyautogui.click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment