forked from AmmeySaini/Edu-Mail-Generator
/
bot.py
121 lines (91 loc) · 3.02 KB
/
bot.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
import time
from selenium import webdriver
import Student
from __colleges import CCC, WCC, LCC, MCC, Stockton
def start_bot():
with open('prefBrowser.txt', 'r') as fp:
browser = fp.read()
try:
# For Chrome
if browser == 'chrome':
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=./selenium")
driver = webdriver.Chrome(options=options, executable_path=r'./webdriver/chromedriver')
# For Firefox
elif browser == 'firefox':
# cap = DesiredCapabilities().FIREFOX
# cap['marionette'] = True
driver = webdriver.Firefox(executable_path=r'./webdriver/geckodriver')
except Exception as e:
time.sleep(0.4)
print('\nError - ' + str(e))
return
driver.maximize_window()
driver.delete_all_cookies()
return driver
def new_application(college):
driver = start_bot()
student = Student.build_student(driver, college)
url = Student.allColleges.get(student.college).get('url')
driver.get(url)
print('Applying to ' + student.college)
if 'opencccapply' in url:
CCC.apply(driver, student)
elif 'westmoreland' in url:
WCC.apply(driver, student)
elif 'lcc' in url:
LCC.apply(driver, student)
# elif 'stockton' in url:
# Stockton.apply(driver, student)
# elif 'mcc' in url:
# MCC.apply(driver, student)
def continue_application():
student: Student.Student
student = Student.get_student_from_file()
if student is None:
print('Something bad happened, try again')
return
print('Applying as ' + student.firstName + ' ' + student.lastName)
driver = start_bot()
WCC.continue_app(driver, student)
def main():
# Check if setup.py has been run
with open('prefBrowser.txt', 'r') as fp:
browser = fp.read()
if browser == '':
print('Run setup.py first!')
return
print('\nKeep an eye on this console!')
time.sleep(2)
print('Select a college:')
colleges = list(Student.allColleges.keys())
for index, college in enumerate(colleges):
print(str(index + 1) + ' - ' + college)
while True:
data = input()
if data == '':
continue
if int(data) > len(Student.allColleges) or int(data) < 1:
print("Invalid response, try again.")
continue
else:
break
college = colleges[int(data) - 1]
print('\nSelected College: ' + college)
if college == 'Westmoreland College':
print('1 - New Application\n2 - Check email and continue application')
while True:
data = input()
if data == '':
continue
if int(data) not in (1, 2):
print("Invalid response, try again.")
continue
else:
break
if int(data) == 2:
continue_application()
return
new_application(college)
if __name__ == '__main__':
main()