-
-
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
base: main
Are you sure you want to change the base?
Conversation
I created a utils package with several modules and moved functions into those modules. |
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.
@alirahmnicode great work!
Here are few more suggestions on how to improve.
@@ -0,0 +1,227 @@ | |||
from typing import List |
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.
To be more explicit, call this file linkedin_url_generator.py as it currently generates link only for Linkedin
def writeResults(text: str): | ||
timeStr = time.strftime("%Y%m%d") | ||
directory = "data" | ||
fileName = "Applied Jobs DATA - " + timeStr + ".txt" | ||
filePath = os.path.join(directory, fileName) | ||
|
||
try: | ||
os.makedirs(directory, exist_ok=True) # Ensure the 'data' directory exists. | ||
|
||
# Open the file for reading and writing ('r+' opens the file for both) | ||
with open(filePath, 'r+', encoding="utf-8") as file: | ||
lines = [] | ||
for line in file: | ||
if "----" not in line: | ||
lines.append(line) | ||
file.seek(0) # Go back to the start of the file | ||
file.truncate() # Clear the file | ||
file.write("---- Applied Jobs Data ---- created at: " + timeStr + "\n") | ||
file.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " + "\n") | ||
for line in lines: | ||
file.write(line) | ||
file.write(text + "\n") | ||
except FileNotFoundError: | ||
with open(filePath, 'w', encoding="utf-8") as f: | ||
f.write("---- Applied Jobs Data ---- created at: " + timeStr + "\n") | ||
f.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " + "\n") | ||
f.write(text + "\n") | ||
except Exception as e: | ||
prRed(f"❌ Error in writeResults: {e}") # Assuming prRed is a function to print errors in red color | ||
|
||
|
||
# def writeResults(text: str): | ||
# timeStr = time.strftime("%Y%m%d") | ||
# fileName = "Applied Jobs DATA - " +timeStr + ".txt" | ||
# try: | ||
# with open("data/" +fileName, encoding="utf-8" ) as file: | ||
# lines = [] | ||
# for line in file: | ||
# if "----" not in line: | ||
# lines.append(line) | ||
|
||
# with open("data/" +fileName, 'w' ,encoding="utf-8") as f: | ||
# f.write("---- Applied Jobs Data ---- created at: " +timeStr+ "\n" ) | ||
# f.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " +"\n" ) | ||
# for line in lines: | ||
# f.write(line) | ||
# f.write(text+ "\n") | ||
|
||
# except: | ||
# with open("data/" +fileName, 'w', encoding="utf-8") as f: | ||
# f.write("---- Applied Jobs Data ---- created at: " +timeStr+ "\n" ) | ||
# f.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " +"\n" ) | ||
|
||
# f.write(text+ "\n") |
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.
I would put this in a file_writer.py or something similar
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.
And after you separate this part, the rest are utils for the webdriver so you can rename it from utils.py -> driver.py
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 comment
The reason will be displayed to describe this comment to others. Learn more.
searchUrl = url_generator.LinkedinUrlGenerator.getGeneralSearchUrl() | |
searchUrl = LinkedinUrlGenerator.getGeneralSearchUrl() |
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.
Adjust the import so you can apply this suggestion
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 |
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
No description provided.