|
| 1 | +import argparse |
| 2 | +from selenium import webdriver |
| 3 | +from selenium.webdriver.common.keys import Keys |
| 4 | +from selenium.webdriver.support.ui import WebDriverWait |
| 5 | +from selenium.webdriver.support import expected_conditions as EC |
| 6 | +from selenium.webdriver.common.by import By |
| 7 | +from time import sleep |
| 8 | +import json |
| 9 | + |
| 10 | +# Xpaths |
| 11 | +xLinkedin = { |
| 12 | + 'xEmail': '//input[@name="session_key"]', |
| 13 | + 'xPass': '//input[@name="session_password"]', |
| 14 | + 'xLogin': '//button[contains(.,"Sign in")]', |
| 15 | + 'xProfile': '//div[@data-control-name="identity_welcome_message"]', |
| 16 | + 'xCertName': '//input[@placeholder="Ex: Microsoft certified network associate security"]', |
| 17 | + 'xCertOrg': '//input[@placeholder="Ex: Microsoft"]', |
| 18 | + 'xCredId': '//input[@id="single-line-text-form-component-profileEditFormElement-CERTIFICATION-profileCertification-ACoAADI-i-oBZzsiExXBGep7oC4p5cgLkd4v7kE-1-licenseNumber"]', |
| 19 | + 'xCredUrl': '//input[@id="single-line-text-form-component-profileEditFormElement-CERTIFICATION-profileCertification-ACoAADI-i-oBZzsiExXBGep7oC4p5cgLkd4v7kE-1-url"]', |
| 20 | + 'xSave': '//button[contains(.,"Save")]' |
| 21 | +} |
| 22 | + |
| 23 | + |
| 24 | +class LinkedIn: |
| 25 | + def __init__(self, email, password): |
| 26 | + self.email = email |
| 27 | + self.password = password |
| 28 | + |
| 29 | + def login(self): |
| 30 | + emailField = driver.find_element_by_xpath(xLinkedin['xEmail']) |
| 31 | + emailField.send_keys(self.email) |
| 32 | + passwordField = driver.find_element_by_xpath(xLinkedin['xPass']) |
| 33 | + passwordField.send_keys(self.password) |
| 34 | + |
| 35 | + submitBtn = driver.find_element_by_xpath(xLinkedin['xLogin']) |
| 36 | + submitBtn.click() |
| 37 | + WebDriverWait(driver, 10).until(EC.presence_of_element_located( |
| 38 | + (By.XPATH, xLinkedin['xProfile']))).click() |
| 39 | + |
| 40 | + def addCertData(self, name, org, credId, credUrl): |
| 41 | + sleep(5) |
| 42 | + currentUrl = driver.current_url |
| 43 | + driver.get(currentUrl+'edit/forms/certification/new/') |
| 44 | + nameInput = WebDriverWait(driver, 10).until(EC.presence_of_element_located( |
| 45 | + (By.XPATH, xLinkedin['xCertName']))) |
| 46 | + nameInput.send_keys(name) |
| 47 | + orgInput = driver.find_element_by_xpath(xLinkedin['xCertOrg']) |
| 48 | + orgInput.send_keys(org) |
| 49 | + sleep(4) |
| 50 | + orgInput.send_keys(Keys.ARROW_DOWN + Keys.ENTER) |
| 51 | + credIdInput = driver.find_element_by_xpath(xLinkedin['xCredId']) |
| 52 | + credIdInput.send_keys(credId) |
| 53 | + credUrlInput = driver.find_element_by_xpath(xLinkedin['xCredUrl']) |
| 54 | + credUrlInput.send_keys(credUrl) |
| 55 | + driver.find_element_by_xpath(xLinkedin['xSave']).click() |
| 56 | + |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + parser = argparse.ArgumentParser( |
| 60 | + description="Add your certifications to your LinkedIn Profile") |
| 61 | + group = parser.add_mutually_exclusive_group() |
| 62 | + |
| 63 | + group.add_argument('-c', '--coursera', type=bool, |
| 64 | + help="Coursera certification", action='store_true') |
| 65 | + group.add_argument('-u', '--udemy', type=bool, |
| 66 | + help="Udemy certification", action='store_true') |
| 67 | + |
| 68 | + args = parser.parse_args() |
| 69 | + |
| 70 | + # set org according to arguments |
| 71 | + if args.udemy: |
| 72 | + org = 'udemy' |
| 73 | + elif args.coursera: |
| 74 | + org = 'coursera' |
| 75 | + |
| 76 | + # Chrome environment setup |
| 77 | + opt = webdriver.ChromeOptions() |
| 78 | + opt.add_argument('--disable-gpu') |
| 79 | + opt.add_argument('--headless') |
| 80 | + driver = webdriver.Chrome( |
| 81 | + executable_path='LinkedIn-Certifications-Manager/chromedriver', options=opt) |
| 82 | + driver.get('https://linkedin.com') |
| 83 | + |
| 84 | + # Get LinkedIn login credentials |
| 85 | + data = json.load(open('LinkedIn-Certifications-Manager/credentials.json')) |
| 86 | + |
| 87 | + linkedIn = LinkedIn(data['linkedin']['email'], |
| 88 | + data['linkedin']['password']) |
| 89 | + linkedIn.login() |
| 90 | + |
| 91 | + # Load course data |
| 92 | + courseData = json.load(open('LinkedIn-Certifications-Manager/data.json')) |
| 93 | + items = courseData[org] |
| 94 | + |
| 95 | + # Add certifications to linkedin |
| 96 | + for item in items: |
| 97 | + name = item['name'] |
| 98 | + credId = item['url'].split('/')[-1] |
| 99 | + credUrl = item['url'] |
| 100 | + linkedIn.addCertData(name=name, org=org, |
| 101 | + credId=credId, credUrl=credUrl) |
| 102 | + print(f'Added: {name}') |
| 103 | + print('Completed!') |
0 commit comments