forked from wodsuz/EasyApplyJobsBot
-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
broke up utils.py into multiple files #39
Open
alirahmnicode
wants to merge
1
commit into
GabeGiro:main
Choose a base branch
from
alirahmnicode:utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,15 +3,15 @@ | |||||
import constants | ||||||
import models | ||||||
import repository_wrapper | ||||||
import utils | ||||||
import warnings | ||||||
from utils import sleeper, url_generator, utils, logger | ||||||
from selenium import webdriver | ||||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException | ||||||
from selenium.webdriver.chrome.service import Service as ChromeService | ||||||
from selenium.webdriver.common.by import By | ||||||
from selenium.webdriver.support import expected_conditions as EC | ||||||
from selenium.webdriver.support.ui import WebDriverWait | ||||||
from utils import prGreen, prRed, prYellow | ||||||
from logger.logger import prGreen, prRed, prYellow | ||||||
from webdriver_manager.chrome import ChromeDriverManager | ||||||
from typing import List | ||||||
|
||||||
|
@@ -53,11 +53,11 @@ def __init__(self): | |||||
prYellow("🔄 Trying to log in linkedin...") | ||||||
try: | ||||||
self.driver.find_element("id","username").send_keys(config.email) | ||||||
utils.sleepInBetweenActions(1,2) | ||||||
sleeper.sleepInBetweenActions(1,2) | ||||||
self.driver.find_element("id","password").send_keys(config.password) | ||||||
utils.sleepInBetweenActions(1, 2) | ||||||
sleeper.sleepInBetweenActions(1, 2) | ||||||
self.driver.find_element("xpath",'//button[@type="submit"]').click() | ||||||
utils.sleepInBetweenActions(3, 7) | ||||||
sleeper.sleepInBetweenActions(3, 7) | ||||||
self.checkIfLoggedIn() | ||||||
except: | ||||||
prRed("❌ Couldn't log in Linkedin by using Chrome. Please check your Linkedin credentials on config files line 7 and 8. If error continue you can define Chrome profile or run the bot on Firefox") | ||||||
|
@@ -77,12 +77,12 @@ def startApplying(self): | |||||
try: | ||||||
jobCounter = models.JobCounter() | ||||||
|
||||||
urlData = utils.LinkedinUrlGenerator().generateSearchUrls() | ||||||
urlData = url_generator.LinkedinUrlGenerator().generateSearchUrls() | ||||||
|
||||||
for url in urlData: | ||||||
self.goToUrl(url) | ||||||
|
||||||
urlWords = utils.urlToKeywords(url) | ||||||
urlWords = url_generator.urlToKeywords(url) | ||||||
|
||||||
try: | ||||||
totalJobs = self.wait.until(EC.presence_of_element_located((By.XPATH, '//small'))).text # TODO - fix finding total jobs | ||||||
|
@@ -111,21 +111,21 @@ def startApplying(self): | |||||
" jobs out of " + str(jobCounter.total) + ".") | ||||||
|
||||||
except Exception as e: | ||||||
utils.logDebugMessage("Unhandled exception in startApplying", utils.MessageTypes.ERROR, e, True) | ||||||
logger.logDebugMessage("Unhandled exception in startApplying", logger.MessageTypes.ERROR, e, True) | ||||||
self.driver.save_screenshot("unhandled_exception.png") | ||||||
with open("page_source_at_unhandled_exception.html", "w") as file: | ||||||
file.write(self.driver.page_source) | ||||||
|
||||||
|
||||||
def goToJobsSearchPage(self): | ||||||
searchUrl = utils.LinkedinUrlGenerator.getGeneralSearchUrl() | ||||||
searchUrl = url_generator.LinkedinUrlGenerator.getGeneralSearchUrl() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjust the import so you can apply this suggestion |
||||||
self.goToUrl(searchUrl) | ||||||
utils.sleepInBetweenActions() | ||||||
sleeper.sleepInBetweenActions() | ||||||
|
||||||
|
||||||
def goToUrl(self, url): | ||||||
self.driver.get(url) | ||||||
utils.sleepInBetweenActions() | ||||||
sleeper.sleepInBetweenActions() | ||||||
|
||||||
|
||||||
def goToJobPage(self, jobID): | ||||||
|
@@ -137,7 +137,7 @@ def goToJobPage(self, jobID): | |||||
def processJob(self, jobID: str, jobCounter: models.JobCounter): | ||||||
jobPage = self.goToJobPage(jobID) | ||||||
jobCounter.total += 1 | ||||||
utils.sleepInBetweenBatches(jobCounter.total) | ||||||
sleeper.sleepInBetweenBatches(jobCounter.total) | ||||||
|
||||||
jobProperties = self.getJobProperties(jobID) | ||||||
repository_wrapper.update_job(jobProperties) | ||||||
|
@@ -195,7 +195,7 @@ def getJobsFromSearchPage(self) -> List[models.JobForVerification]: | |||||
title=jobTitle, | ||||||
company=companyName)) | ||||||
else: | ||||||
utils.logDebugMessage("Couldn't find jobID, jobTitle or companyName", utils.MessageTypes.WARNING) | ||||||
logger.logDebugMessage("Couldn't find jobID, jobTitle or companyName", logger.MessageTypes.WARNING) | ||||||
|
||||||
return jobsForVerification | ||||||
|
||||||
|
@@ -275,7 +275,7 @@ def getJobProperties(self, jobID: str) -> models.Job: | |||||
jobPostedDate = self.getJobPostedDate(primary_description_div) | ||||||
numberOfApplicants = self.getNumberOfApplicants(primary_description_div) | ||||||
else: | ||||||
utils.logDebugMessage("in getting primary_description_div", utils.MessageTypes.WARNING) | ||||||
logger.logDebugMessage("in getting primary_description_div", logger.MessageTypes.WARNING) | ||||||
|
||||||
return models.Job( | ||||||
title=jobTitle, | ||||||
|
@@ -295,7 +295,7 @@ def getJobTitle(self): | |||||
try: | ||||||
jobTitle = self.getJobTitleMethod2() | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("in getting jobTitle", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("in getting jobTitle", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobTitle | ||||||
|
||||||
|
@@ -327,7 +327,7 @@ def getJobCompanyMethod1(self, primary_description_div): | |||||
jobCompanyLink = primary_description_div.find_element(By.CSS_SELECTOR, "a.app-aware-link") | ||||||
jobCompany = jobCompanyLink.text.strip() | ||||||
else: | ||||||
utils.logDebugMessage("in getting jobCompany", utils.MessageTypes.WARNING) | ||||||
logger.logDebugMessage("in getting jobCompany", logger.MessageTypes.WARNING) | ||||||
|
||||||
return jobCompany | ||||||
|
||||||
|
@@ -341,7 +341,7 @@ def getJobCompanyMethod2(self): | |||||
jobCompany = jobCompanyElement.text.strip() | ||||||
|
||||||
else: | ||||||
utils.logDebugMessage("in getting jobCompany card", utils.MessageTypes.WARNING) | ||||||
logger.logDebugMessage("in getting jobCompany card", logger.MessageTypes.WARNING) | ||||||
|
||||||
return jobCompany | ||||||
|
||||||
|
@@ -353,7 +353,7 @@ def getJobLocation(self, primary_description_div): | |||||
jobLocationSpan = primary_description_div.find_element(By.XPATH, ".//span[contains(@class, 'tvm__text--low-emphasis')][1]") | ||||||
jobLocation = jobLocationSpan.text.strip() | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("in getting jobLocation", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("in getting jobLocation", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobLocation | ||||||
|
||||||
|
@@ -365,7 +365,7 @@ def getJobPostedDate(self, primary_description_div): | |||||
postedDateSpan = primary_description_div.find_element(By.XPATH, ".//span[contains(@class, 'tvm__text--low-emphasis')][3]") | ||||||
jobPostedDate = postedDateSpan.text.strip() | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("Error in getting jobPostedDate", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("Error in getting jobPostedDate", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobPostedDate | ||||||
|
||||||
|
@@ -377,7 +377,7 @@ def getNumberOfApplicants(self, primary_description_div): | |||||
applicationsSpan = primary_description_div.find_element(By.XPATH, ".//span[contains(@class, 'tvm__text--low-emphasis')][5]") | ||||||
jobApplications = applicationsSpan.text.strip() | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("Error in getting jobApplications", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("Error in getting jobApplications", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobApplications | ||||||
|
||||||
|
@@ -388,7 +388,7 @@ def getJobWorkPlaceType(self): | |||||
try: | ||||||
jobWorkPlaceType = self.driver.find_element(By.XPATH,"//span[contains(@class, 'workplace-type')]").get_attribute("innerHTML").strip() | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("in getting jobWorkPlaceType", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("in getting jobWorkPlaceType", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobWorkPlaceType | ||||||
|
||||||
|
@@ -400,7 +400,7 @@ def getJobDescription(self): | |||||
try: | ||||||
jobDescription = self.driver.find_element(By.XPATH, "//div[contains(@class, 'job-details-jobs')]//div").text.replace("·", "|") | ||||||
except Exception as e: | ||||||
utils.logDebugMessage("in getting jobDescription: ", utils.MessageTypes.WARNING, e) | ||||||
logger.logDebugMessage("in getting jobDescription: ", logger.MessageTypes.WARNING, e) | ||||||
|
||||||
return jobDescription | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OPTIONAL: Remove direct usage of prGreen, prRed, prYellow outside of logger.
This suggestion is optional and can be done in a separate PR