-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreply_vacancy_manager.py
143 lines (95 loc) · 4.08 KB
/
reply_vacancy_manager.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
import datetime
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
NOT_RELEVANT_VACANCY_TEXT = "⚠️ The vacancy has significantly higher requirements for work experience than indicated in your profile."
COVER_LETTER = "Hi,\n\npls check my attached CV and Portfolio portfolio-page-alpha-black.vercel.app\n\nthank you and have a great day\n\nwith bstgds\n\nY. Kolbaiev"
class VacancyManager:
def __init__(self, driver, category):
self.category = category
self.driver = driver
self.yesterday_vacancies = self.get_vacancies()
def get_vacancies(self):
print(f"Getting vacancies for {self.category}")
self.driver.get(f"https://jobs.dou.ua/vacancies/?category={self.category}")
sleep(3)
yesterday = (datetime.date.today() - datetime.timedelta(days=1)).strftime(
"%d %B"
)
vacancies = self.driver.find_elements(By.CSS_SELECTOR, ".l-vacancy .date")
yesterday_vacancies = []
for vacancy in vacancies:
if not vacancy.text:
continue
if yesterday == vacancy.text:
yesterday_vacancies.append(vacancy)
return yesterday_vacancies
def vacancy_manager(self):
if not self.yesterday_vacancies:
print(f"No vacancies for {self.category} found")
return
for vacancy in self.yesterday_vacancies:
sibling = vacancy.find_element(By.XPATH, "./following-sibling::div")
link = sibling.find_element(By.TAG_NAME, "a")
link.send_keys(Keys.CONTROL + Keys.RETURN)
sleep(5)
self.driver.switch_to.window(self.driver.window_handles[1])
sleep(3)
try:
skip_vacancy = self.vacancy_not_relevant()
if skip_vacancy:
continue
except Exception:
print("Vacancy is relevant")
try:
self.apply_for_vacancy()
except Exception:
self.vacancy_with_external_link()
sleep(3)
print(f"All ${self.category} vacancies processed successfully")
def vacancy_not_relevant(self):
not_relevant_vacancy = self.driver.find_element(
By.XPATH,
'//*[@id="container"]/div[2]/div/div[2]/div[1]/div/div[4]/div[3]',
)
if not_relevant_vacancy.text == NOT_RELEVANT_VACANCY_TEXT:
print("Vacancy is not relevant")
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])
return True
def apply_for_vacancy(self):
apply_button = self.driver.find_element(By.XPATH, '//*[@id="reply-btn-id"]')
apply_button.click()
sleep(3)
cover_letter = self.driver.find_element(By.XPATH, '//*[@id="reply_descr"]')
cover_letter.send_keys(COVER_LETTER)
sleep(2)
file_input = self.driver.find_element(By.XPATH, '//*[@id="reply_file"]')
file_input.send_keys("D:/PYTHON/CODE/DAY102DOU_APPLICATION_BOT/data/C_V.pdf")
sleep(2)
submit_button = self.driver.find_element(
By.XPATH, '//*[@id="replied-id"]/button'
)
submit_button.click()
sleep(5)
print("Application sent")
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])
def vacancy_with_external_link(self):
try:
external_link = self.driver.find_element(
By.CSS_SELECTOR, ".replied-external"
)
print(
f"Apply button leeds to external website. Link: {external_link.get_attribute('href')}"
)
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])
except Exception:
print("External link not found. Probably you already applied")
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])