diff --git a/naukri.py b/naukri.py index 07e2561..d9ee48e 100644 --- a/naukri.py +++ b/naukri.py @@ -4,6 +4,7 @@ import re import os +import io import sys import time import logging @@ -14,7 +15,8 @@ from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException from PyPDF2 import PdfFileReader, PdfFileWriter -import random, string, io +from string import ascii_uppercase, digits +from random import choice, randint from datetime import datetime from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter @@ -141,6 +143,10 @@ def tearDown(driver): pass +def randomText(): + return "".join(choice(ascii_uppercase + digits) for _ in range(randint(1, 5))) + + def LoadNaukri(headless): """Open Chrome to load Naukri.com""" options = webdriver.ChromeOptions() @@ -176,6 +182,7 @@ def naukriLogin(headless = False): if "naukri" in driver.title.lower(): log_msg("Website Loaded Successfully.") + emailFieldElement = None if is_element_present(driver, By.ID, "emailTxt"): emailFieldElement = GetElement(driver, "emailTxt", locator="ID") time.sleep(1) @@ -288,10 +295,7 @@ def UpdateProfile(driver): def UpdateResume(): try: # random text with with random location and size - txt = "".join( - random.choice(string.ascii_uppercase + string.digits) - for _ in range(random.randint(1, 10)) - ) + txt = randomText() xloc = random.randint(700, 1000) # this ensures that text is 'out of page' fsize = random.randint(1, 10) diff --git a/requirements.txt b/requirements.txt index 92afdd2..179073e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ +reportlab==3.5.48 +webdriver_manager==3.2.2 selenium==3.141.0 -webdriver-manager==3.1.0 PyPDF2==1.26.0 -reportlab==3.5.44 diff --git a/test.py b/test.py index 7c03c3a..f84886f 100644 --- a/test.py +++ b/test.py @@ -1,12 +1,13 @@ import unittest import naukri + class Test(unittest.TestCase): def test_naukri(self): - (status, driver) = naukri.naukriLogin(headless = True) + (status, driver) = naukri.naukriLogin(headless=True) naukri.tearDown(driver) self.assertFalse(status) -if __name__ == '__main__': - unittest.main() +if __name__ == "__main__": + unittest.main()