forked from SeanDaBlack/KelloggBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
293 lines (242 loc) · 11.4 KB
/
main.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import requests
import functools
import os
import random
import re
import sys
import time
import argparse
from selenium.webdriver.chrome import options
from faker import Faker
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from resume_faker import make_resume
from pdf2image import convert_from_path
from webdriver_manager.chrome import ChromeDriverManager
os.environ['WDM_LOG_LEVEL'] = '0'
from constants.common import *
from constants.elementIds import *
from constants.email import *
from constants.location import *
from constants.parser import *
from constants.urls import *
from constants.xPaths import *
from constants.areaCodes import *
fake = Faker()
# Add printf: print with flush by default. This is for python 2 support.
# https://stackoverflow.com/questions/230751/how-can-i-flush-the-output-of-the-print-function-unbuffer-python-output#:~:text=Changing%20the%20default%20in%20one%20module%20to%20flush%3DTrue
printf = functools.partial(print, flush=True)
#Option parsing
parser = argparse.ArgumentParser(SCRIPT_DESCRIPTION,epilog=EPILOG)
parser.add_argument('--debug',action='store_true',default=DEBUG_DISABLED,required=False,help=DEBUG_DESCRIPTION,dest='debug')
parser.add_argument('--mailtm',action='store_true',default=MAILTM_DISABLED,required=False,help=MAILTM_DESCRIPTION,dest='mailtm')
args = parser.parse_args()
# END TEST
def start_driver(random_city):
options = Options()
if (args.debug == DEBUG_DISABLED):
options.add_argument(f"user-agent={USER_AGENT}")
options.add_argument('disable-blink-features=AutomationControlled')
options.headless = True
driver = webdriver.Chrome(ChromeDriverManager().install(),options=options)
driver.set_window_size(1440, 900)
elif (args.debug == DEBUG_ENABLED):
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(CITIES_TO_URLS[random_city])
driver.implicitly_wait(10)
time.sleep(15)
#WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, CREATE_AN_ACCOUNT_BUTTON)))
driver.find_element_by_xpath(APPLY_NOW_BUTTON_1).click()
driver.find_element_by_xpath(APPLY_NOW_BUTTON_2).click()
driver.find_element_by_xpath(CREATE_AN_ACCOUNT_BUTTON).click()
return driver
def generate_account(driver, fake_identity):
# make fake account info and fill
email = fake.free_email()
password = fake.password()
for key in XPATHS_2.keys():
if key in ('email', 'email-retype'):
info = fake_identity['email']
elif key in ('pass', 'pass-retype'):
info = password
elif key == 'first_name':
info = fake_identity['first_name']
elif key == 'last_name':
info = fake_identity['last_name']
elif key == 'pn':
info = fake_identity['phone']
driver.find_element_by_xpath(XPATHS_2.get(key)).send_keys(info)
time.sleep(random.randint(0, 2))
select = Select(driver.find_element_by_id(COUNTRY_REGION_CODE_LABEL))
select.select_by_value(COUNTRY_CODE_US)
select = Select(driver.find_element_by_id(COUNTRY_REGION_OF_RESIDENCE_LABEL))
select.select_by_value(COUNTRY_CODE_US)
driver.find_element_by_xpath(READ_ACCEPT_DATA_PRIVACY_STATEMENT_ANCHORTAG).click()
time.sleep(1.5)
driver.find_element_by_xpath(ACCEPT_BUTTON).click()
time.sleep(2)
driver.find_element_by_xpath(CREATE_ACCOUNT_BUTTON).click()
time.sleep(1.5)
for i in range(120):
time.sleep(1.5)
if (args.mailtm == MAILTM_DISABLED):
mail = requests.get(f'https://api.guerrillamail.com/ajax.php?f=check_email&seq=1&sid_token={fake_identity.get("sid")}').json().get('list')
if mail:
passcode = re.findall('(?<=n is ).*?(?=<)', requests.get(f'https://api.guerrillamail.com/ajax.php?f=fetch_email&email_id={mail[0].get("mail_id")}&sid_token={fake_identity.get("sid")}').json().get('mail_body'))[0]
break
elif (args.mailtm == MAILTM_ENABLED):
mail = requests.get("https://api.mail.tm/messages?page=1", headers={'Authorization':f'Bearer {fake_identity.get("sid")}'}).json().get('hydra:member')
if mail:
passcode = re.findall('(?<=n is ).*', requests.get(f'https://api.mail.tm{mail[0].get("@id")}', headers={'Authorization':f'Bearer {fake_identity.get("sid")}'}).json().get('text'))[0]
break
else:
args.mailtm ^= True
main() # I should probably find a better way to do this.
driver.find_element_by_xpath(VERIFY_EMAIL_INPUT).send_keys(passcode)
driver.find_element_by_xpath(VERIFY_EMAIL_BUTTON).click()
printf(f"successfully made account for fake email {email}")
def fill_out_application_and_submit(driver, random_city, fake_identity):
# make resume
resume_filename = fake_identity['last_name']+'-Resume'
make_resume(fake_identity['first_name']+' '+fake_identity['last_name'], fake_identity['email'], fake_identity['phone'], resume_filename)
images = convert_from_path(resume_filename+'.pdf')
images[0].save(resume_filename+'.png', 'PNG')
# wait for page to load
WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, PROFILE_INFORMATION_DROPDOWN)))
# fill out form parts of app
driver.find_element_by_xpath(PROFILE_INFORMATION_DROPDOWN).click()
driver.find_element_by_xpath(CANDIDATE_SPECIFIC_INFORMATION_DROPDOWN).click()
for key in XPATHS_1.keys():
if key == 'resume':
driver.find_element_by_xpath(UPLOAD_A_RESUME_BUTTON).click()
info = os.getcwd() + '/'+resume_filename+'.png'
elif key == 'addy':
info = fake.street_address()
elif key == 'city':
info = random_city
elif key == 'zip':
info = CITIES_TO_ZIP_CODES[random_city]
elif key == 'job':
info = fake.job()
elif key == 'salary':
first = random.randrange(15000, 30000, 5000)
info = f'{format(first, ",")}-{format(random.randrange(first + 5000, 35000, 5000), ",")}'
driver.find_element_by_xpath(XPATHS_1.get(key)).send_keys(info)
printf(f"successfully filled out app forms for {random_city}")
# fill out dropdowns
select = Select(driver.find_element_by_id(CITIZEN_QUESTION_LABEL))
select.select_by_visible_text(YES)
select = Select(driver.find_element_by_id(COUNTRY_OF_ORIGIN_LABEL))
select.select_by_visible_text(FULL_NAME_US)
select = Select(driver.find_element_by_id(EIGHTEEN_YEARS_OLD_LABEL))
select.select_by_visible_text(YES)
select = Select(driver.find_element_by_id(REQUIRE_SPONSORSHIP_LABEL))
select.select_by_visible_text(NO)
select = Select(driver.find_element_by_id(PREVIOUSLY_WORKED_LABEL))
select.select_by_visible_text(NO)
select = Select(driver.find_element_by_id(PREVIOUSLY_PARTNERED_LABEL))
select.select_by_visible_text(NO)
select = Select(driver.find_element_by_id(RELATIVE_WORKER_LABEL))
select.select_by_visible_text(NO)
select = Select(driver.find_element_by_id(ESSENTIAL_FUNCTIONS_LABEL))
select.select_by_visible_text(YES)
select = Select(driver.find_element_by_id(PREVIOUSLY_PARTNERED_LABEL))
select.select_by_visible_text(NO)
time.sleep(1)
select = Select(driver.find_element_by_id(GENDER_LABEL))
gender = random.choice(GENDERS_LIST)
select.select_by_visible_text(gender)
driver.find_element_by_xpath(MIXER_QUESTION_1_LABEL).click()
driver.find_element_by_xpath(MIXER_QUESTION_2_LABEL).click()
els = driver.find_elements_by_xpath(LONG_PERIODS_QUESTION_LABEL)
[el.click() for el in els]
time.sleep(5)
driver.find_element_by_xpath(APPLY_BUTTON).click()
printf(f"successfully submitted application")
# take out the trash
os.remove(resume_filename+'.pdf')
os.remove(resume_filename+'.png')
def random_email(name=None):
if name is None:
name = fake.name()
mailGens = [lambda fn, ln, *names: fn + ln,
lambda fn, ln, *names: fn + "_" + ln,
lambda fn, ln, *names: fn[0] + "_" + ln,
lambda fn, ln, *names: fn + ln + str(int(1 / random.random() ** 3)),
lambda fn, ln, *names: fn + "_" + ln + str(int(1 / random.random() ** 3)),
lambda fn, ln, *names: fn[0] + "_" + ln + str(int(1 / random.random() ** 3)), ]
return random.choices(mailGens, MAIL_GENERATION_WEIGHTS)[0](*name.split(" ")).lower() + "@" + \
requests.get('https://api.mail.tm/domains').json().get('hydra:member')[0].get('domain')
def random_phone(format=None):
area_code = str(random.choice(AREA_CODES))
middle_three = str(random.randint(0,999)).rjust(3,'0')
last_four = str(random.randint(0,9999)).rjust(4,'0')
if format is None:
format = random.randint(0,4)
if format==0:
return area_code+middle_three+last_four
elif format==1:
return area_code+' '+middle_three+' '+last_four
elif format==2:
return area_code+'.'+middle_three+'.'+last_four
elif format==3:
return area_code+'-'+middle_three+'-'+last_four
elif format==4:
return '('+area_code+') '+middle_three+'-'+last_four
def random_identity():
fake_first_name = fake.first_name()
fake_last_name = fake.last_name()
fake_phone = random_phone()
try:
if (args.mailtm == MAILTM_DISABLED):
printf(f"USING GUERRILLA TO CREATE EMAIL")
response = requests.get('https://api.guerrillamail.com/ajax.php?f=get_email_address').json()
fake_email = response.get('email_addr')
mail_sid = response.get('sid_token')
printf(f"EMAIL CREATED")
elif (args.mailtm == MAILTM_ENABLED):
printf(f"USING MAILTM TO CREATE EMAIL")
fake_email = requests.post('https://api.mail.tm/accounts', data='{"address":"'+random_email(fake_first_name+' '+fake_last_name)+'","password":" "}', headers={'Content-Type': 'application/json'}).json().get('address')
mail_sid = requests.post('https://api.mail.tm/token', data='{"address":"'+fake_email+'","password":" "}', headers={'Content-Type': 'application/json'}).json().get('token')
printf(f"EMAIL CREATED")
except:
args.mailtm ^= True
return random_identity()
return {
'first_name': fake_first_name,
'last_name': fake_last_name,
'email': fake_email,
'phone': fake_phone,
'sid' : mail_sid
}
def main():
while True:
random_city = random.choice(list(CITIES_TO_URLS.keys()))
try:
driver = start_driver(random_city)
except Exception as e:
printf(f"FAILED TO START DRIVER: {e}")
pass
time.sleep(2)
fake_identity = random_identity()
try:
generate_account(driver, fake_identity)
except Exception as e:
printf(f"FAILED TO CREATE ACCOUNT: {e}")
pass
try:
fill_out_application_and_submit(driver, random_city, fake_identity)
except Exception as e:
printf(f"FAILED TO FILL OUT APPLICATION AND SUBMIT: {e}")
pass
driver.close()
continue
driver.close()
time.sleep(5)
if __name__ == '__main__':
main()
sys.exit()