-
Notifications
You must be signed in to change notification settings - Fork 0
/
secureLI.py
135 lines (109 loc) · 4.49 KB
/
secureLI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import re
from selenium.webdriver.common.by import By
from securer import Securer, long_wait, pause_pre_quit, short_wait
class Url:
main = "https://www.linkedin.com"
ad_base_url = "https://www.linkedin.com/psettings/advertising"
ad_types = [
"profile-data",
"li-enterprise-product",
"connections",
"location",
"demographics",
"companies-followed",
"groups-joined",
"education",
"job-information",
"employer",
"websites-visited",
"ads-beyond-linkedin",
"actions-that-showed-interest",
"actions-after-viewing-ads",
]
public_profile = "https://www.linkedin.com/public-profile/settings" # Record setting
settings = "https://www.linkedin.com/psettings"
class LoginFieldId:
user = "session_key"
pwd = "session_password"
submit = '//button[@type="submit"]'
class Xpath:
about = '//section[div[@id="about"]]/div[3]/div/div/div/span[1]'
checked = "//input[@checked]"
checked_box = '//div[@class="checkbox-input" and input[@checked]]/label/p'
checked_switch = '//div[@class="toggle-input" and input[@checked]]/label/p'
profile = '//a[@href and @class="ember-view block"]'
public_visibility = '//div[input[@id="toggle-visibilityLevel" and @checked]]/label/span[1]'
unchecked = "//input[not(@checked)]"
class SecureLI(Securer):
def __init__(self):
super().__init__("linkedin")
def connect(self):
self.login(Url.main, LoginFieldId.user, LoginFieldId.pwd)
self.wait_and_click(Xpath.profile, click=False)
def close(self):
pause_pre_quit()
self.cleanup()
def check_about(self):
self.driver.find_element(By.XPATH, Xpath.profile).click()
long_wait()
summary = self.driver.find_element(By.XPATH, Xpath.about).text
print(summary)
if re.search(r"\d{10}", summary) is not None:
self.log("About/Summary contains your mobile number")
def public_profile(self):
id_map = {
"currentPositions": "currentPositionsDetails",
"currentPositionsDetails": "currentPositions",
"pastPositions": "pastPositionsDetails",
"pastPositionsDetails": "pastPositions",
"educations": "educationsDetails",
"educationsDetails": "educations",
}
def filter_fields(field_list, checked=True):
filtered_fields = []
for field in field_list:
if "--" in field:
field = field.split("--")[1]
field = id_map.get(field, field)
filtered_fields.append(field)
elif field.endswith("pictureVisibilityLevel") and checked:
field = field.split("-")[0]
self.log(f"Picture visibility level is {field}")
return filtered_fields
self.driver.get(Url.public_profile)
short_wait()
public_profile = self.driver.find_elements(By.XPATH, Xpath.public_visibility)
if not public_profile:
self.log("Your profile is private to LinkedIn")
return 0
checked_fields = (x.get_attribute("id") for x in self.driver.find_elements(By.XPATH, Xpath.checked))
unchecked_fields = (x.get_attribute("id") for x in self.driver.find_elements(By.XPATH, Xpath.unchecked))
self.log(f"OLD:\nVisible in timeline : {filter_fields(checked_fields, checked=True)}")
self.log(f"Not Visible in timeline : {filter_fields(unchecked_fields, checked=False)}")
public_profile[0].click()
self.log("NEW:\nYour profile is set to private")
def ads(self):
def uncheck(xpath):
toggles = self.driver.find_elements(By.XPATH, xpath)
for toggle in toggles:
toggle.click()
self.driver.get(Url.ad_base_url)
for ad_type in Url.ad_types:
self.driver.get(f"{Url.ad_base_url}/{ad_type}")
short_wait()
uncheck(Xpath.checked_switch)
uncheck(Xpath.checked_box)
self.log("All Advertisement data unchecked")
def secure_all(self):
steps = [self.connect, self.check_about, self.public_profile, self.ads, self.close]
for step in steps:
step()
def main():
my_linkedin = SecureLI()
if my_linkedin.username and my_linkedin.password:
my_linkedin.secure_all()
else:
my_linkedin.log("No username/password found")
my_linkedin.cleanup()
if __name__ == "__main__":
main()