def add(self): time.sleep(1) self.driver.get(self.candidate_url) time.sleep(3) signedin_to_ats = self.check_signed_in_to_ats() if not signedin_to_ats: return Result.failure('Sign in to ATS first') profile_in_ats = self.check_profile_in_ats() if profile_in_ats: return Result.success( f'Profile in ATS {unquote(self.candidate_url)}') save_to_ats_pressed = self.press_save_to_ats_button() if not save_to_ats_pressed: return Result.failure( f'Save to ATS button was' f' not present for {unquote(self.candidate_url)}') self.try_save_to_new_vacancy() vacancy_selected = self.select_vacancy() if not vacancy_selected: Result.failure(f'Can not find \'{self.vacancy}\' in ATS options') self.press_add_to_vacancy_in_ats() return Result.success( f'{unquote(self.candidate_url)} added to ATS database')
def validate_pages(self): if not self.args.pages: return Result.failure('Heri, provide please pages' ' parameter or use --help ;)') for page in self.args.pages.split(','): if not validators.between(int(page), min=1, max=settings.MAX_PAGE): return Result.failure(f"{page} page out of range," f" max is {settings.MAX_PAGE}") return Result.success()
def validate_proxy(self): if not self.args.proxy: return Result.success() try: host, port = self.args.proxy.split(':') except ValueError: return Result.failure('Port is not provided, may be "80"?' ' Proxy example: "142.250.75.14:80"') if self.args.proxy and not validators.ipv4(host): return Result.failure('Heri, provide please proxy like' ' "142.250.75.14:80" or use --help ;)') return Result.success()
def validate_engine(self): if not self.args.engine: return Result.success() if self.args.engine not in ['g', 'l']: return Result.failure('Heri, provide please engine ' 'like "g" (Google) or "l" (Linkedin)') return Result.success()
def go_to_page(self, page): if page == 1: return Result.success() previous_last_visible_page = None while True: try: pagination_button = self.driver.find_element_by_link_text( str(page)) pagination_button.click() return Result.success() except selenium.common.exceptions.NoSuchElementException: pass last_visible_page = self.click_last_visible_page() if previous_last_visible_page and last_visible_page <= previous_last_visible_page: return Result.failure( f"Searchable page is out of range, last page:" f" {previous_last_visible_page}, searchable page: {page}") previous_last_visible_page = last_visible_page if settings.MAX_PAGE <= last_visible_page: return Result.failure(f"MAX_PAGE reached")
def search(self): self.driver.get(settings.LINKEDIN_URL) self.enter_query() linkedin_urls = [] for page in self.pages: navigated = LinkedinPaginator(driver=self.driver, page=page).go_to_page() if not navigated: return Result.failure(f'Pagination error: page {page}') linkedin_urls = linkedin_urls + self.find_linkedin_urls() return Result.success(linkedin_urls)
def validate(self): if not self.args.query: return Result.failure('Heri, provide please query' ' parameter or use --help ;)') result = self.validate_pages() if result.is_failure(): return result result = self.validate_proxy() if result.is_failure(): return result result = self.validate_engine() if result.is_failure(): return result return Result.success()