This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selenium_southwest.py
198 lines (153 loc) · 6.95 KB
/
selenium_southwest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# Ian Cleary
# https://github.com/iancleary
# https://github.com/iancleary/airline-check-in
# clearyia@gmail.com
import os
import time # sleep
from selenium import webdriver # Browswer Automation
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import threading # multi thread browsers to log in all passengers at the same time
#from exceptions import Exception
##############################################################################
##############################################################################
####################### Only Edit Below Passenger List #######################
##############################################################################
##############################################################################
# Login list (confirmationNumber, firstName, lastName, 'email' or 'text', area code, phone prefix, phone number, email address)
# append as many users as desired
passengerList = []
passengerList.append(['M48GBP', 'Ian', 'Cleary', 'text', '4805551234', 'myemail@gmail.com'])
##############################################################################
##############################################################################
####################### Only Edit Above Passenger List #######################
##############################################################################
##############################################################################
# Site Information
URL = 'https://www.southwest.com/flight/retrieveCheckinDoc.html?clk=GSUBNAV-CHCKIN&forceNewSession=yes'
DEBUG_XPATH = True
DEBUG_CHROMEDRIVER_PATH = True
HEADLESS = False
FIRST_SCREEN_ATTEMPTS = 0
SECOND_SCREEN_ATTEMPTS = 0
THIRD_SCREEN_ATTEMPTS = 0
#############################################################################
import os
def clear():
os.system('cls' if os.name == 'nt' else 'clear')
# functions to enter username, password, and click login
def text_autofill(driver, text_xpath, text):
text_box = driver.find_element_by_xpath(text_xpath)
text_box.send_keys(text)
return
def text_clear(driver, text_xpath):
text_box = driver.find_element_by_xpath(text_xpath).clear()
return
def click(driver, webElement_xpath):
driver.find_element_by_xpath(webElement_xpath).click()
return
#############################################################################
# Functions to script each log in screen
def firstScreen(driver, passenger):
global FIRST_SCREEN_ATTEMPTS
confirmationNumber_xpath = '//*[@id="confirmationNumber"]'
firstName_xpath = '//*[@id="passengerFirstName"]'
lastName_xpath = '//*[@id="passengerLastName"]'
checkIn_xpath = '//*[@id="form-mixin--submit-button"]' #Check In button
text_autofill(driver, confirmationNumber_xpath, passenger[0])
text_autofill(driver, firstName_xpath, passenger[1])
text_autofill(driver, lastName_xpath, passenger[2])
time.sleep(1)
click(driver, checkIn_xpath)
if DEBUG_XPATH:
clear()
print("1st screen: %s %s: Attempt %i" % (passenger[1], passenger[2], FIRST_SCREEN_ATTEMPTS))
FIRST_SCREEN_ATTEMPTS = FIRST_SCREEN_ATTEMPTS + 1
return
def secondScreen(driver, passenger):
global SECOND_SCREEN_ATTEMPTS
#checkIn_2nd_Screen_xpath = '//*[@id="printDocumentsButton"]'
checkIn_2nd_Screen_xpath = '//*[@id="swa-content"]/div/div[2]/div/section/div/div/div[3]/button'
click(driver, checkIn_2nd_Screen_xpath)
time.sleep(1)
if DEBUG_XPATH:
clear()
print("2nd screen: %s %s: Attempt %i" % (passenger[1], passenger[2], SECOND_SCREEN_ATTEMPTS))
SECOND_SCREEN_ATTEMPTS = SECOND_SCREEN_ATTEMPTS + 1
return
def thirdScreen(driver, passenger):
print_button_xpath = '//*[@id="swa-content"]/div/div[2]/div/section/div/div/section/table/tbody/tr/td[1]/button'
email_button_xpath = '//*[@id="swa-content"]/div/div[2]/div/section/div/div/section/table/tbody/tr/td[2]/button'
email_textBox_xpath = '//*[@id="emailBoardingPass"]'
email_send_xpath = '//*[@id="form-mixin--submit-button"]'
text_button_xpath = '//*[@id="swa-content"]/div/div[2]/div/section/div/div/section/table/tbody/tr/td[3]/button'
text_phone_number_xpath = '//*[@id="textBoardingPass"]'
text_phone_number_send_xpath = '//*[@id="form-mixin--submit-button"]'
if(passenger[3] == 'text'):
click(driver, text_button_xpath)
time.sleep(1)
text_autofill(driver, text_phone_number_xpath, passenger[4])
click(driver, text_phone_number_send_xpath)
elif(passenger[3] == 'email'):
click(driver, email_button_xpath)
time.sleep(1)
text_autofill(driver, email_textBox_xpath, passenger[5])
click(driver, email_send_xpath)
return
#############################################################################
def loginSinglePassenger(passenger):
cwd = os.getcwd()
path_to_chromedriver = '%s/chromedriver' % (cwd)
chrome_options = Options()
chrome_options.add_argument("--headless")
if DEBUG_CHROMEDRIVER_PATH:
print(path_to_chromedriver)
if HEADLESS:
driver = webdriver.Chrome(path_to_chromedriver, chrome_options=chrome_options) # faster with one driver for entire list
else:
driver = webdriver.Chrome(path_to_chromedriver) # faster with one driver for entire list
driver.get(URL)
#time.sleep(1)
firstScreen(driver, passenger)
time.sleep(2)
#loop first screen until second screen appears (will only go through exactly 24 hours before flight)
passFirstScreen = False
while (passFirstScreen == False):
try:
secondScreen(driver, passenger)
passFirstScreen = True
except NoSuchElementException:
driver.get(URL)
firstScreen(driver, passenger)
# now third screen
#time.sleep(1)
thirdScreen(driver, passenger)
time.sleep(10)
driver.quit()
return
#############################################################################
# Threading class
class myThread (threading.Thread):
def __init__(self, threadID, name, counter, passenger):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
self.passenger = passenger
def run(self):
print("Starting " + self.name + "\n")
loginSinglePassenger(self.passenger)
print("Exiting " + self.name + "\n")
#############################################################################
# Main Login with MultiThreading
def login(passengerList):
threads = []
for passengerIndex,passenger in enumerate(passengerList):
thread = myThread(passengerIndex, "Thread-" + str(passengerIndex), passengerIndex, passenger)
threads.append(thread)
for passengerIndex,passenger in enumerate(passengerList):
threads[passengerIndex].start()
print("Exiting Main Thread")
return
# Main Code Block
login(passengerList)