5
5
6
6
logger = logging .getLogger (__name__ )
7
7
8
+
8
9
class GoogleSearchAPI :
9
10
def __init__ (self , key : str , cx : str ):
10
11
self ._cx = cx
@@ -24,7 +25,8 @@ def _hit_api(self, linkedin_id: str) -> list:
24
25
while True :
25
26
resp = requests .get (self ._api_url , params = params )
26
27
if resp .status_code != 200 :
27
- logger .warning (f"Google Custom Search API error: { resp .status_code } - { resp .text } " )
28
+ logger .warning (
29
+ f"Google Custom Search API error: { resp .status_code } - { resp .text } " )
28
30
break
29
31
30
32
data = resp .json ()
@@ -39,6 +41,7 @@ def _hit_api(self, linkedin_id: str) -> list:
39
41
logger .exception ("Error in _hit_api:" )
40
42
return results
41
43
44
+
42
45
class ProfilePicture :
43
46
def __init__ (self , key : str , cx : str ):
44
47
self ._api_obj = GoogleSearchAPI (key , cx )
@@ -54,7 +57,8 @@ def extract_id(self, link: str) -> str:
54
57
return linkedin_id
55
58
56
59
def _check_picture_url (self , link : str ) -> bool :
57
- match = re .search (r"(media-exp\d\.licdn\.com).+?(profile-displayphoto-shrink_)" , link )
60
+ match = re .search (
61
+ r"(media-exp\d\.licdn\.com).+?(profile-displayphoto-shrink_)" , link )
58
62
return bool (match )
59
63
60
64
def _check_url_exists (self , link : str ) -> bool :
@@ -71,7 +75,8 @@ def _extract_profile_picture(self, linkedin_id: str, res: list) -> str:
71
75
search_id = self .extract_id (linkedin_url )
72
76
if search_id == linkedin_id :
73
77
metatags = item .get ("pagemap" , {}).get ("metatags" , [])
74
- metatags = [tag .get ("og:image" ) for tag in metatags if "og:image" in tag ]
78
+ metatags = [tag .get ("og:image" )
79
+ for tag in metatags if "og:image" in tag ]
75
80
76
81
for url in metatags :
77
82
if self ._check_picture_url (url ) and self ._check_url_exists (url ):
@@ -96,7 +101,8 @@ def _extract_profile_info(self, linkedin_id: str, res: list) -> dict:
96
101
def get_profile_picture (self , link : str ) -> str :
97
102
linkedin_id = self .extract_id (link )
98
103
api_resp = self ._api_obj ._hit_api (linkedin_id )
99
- profile_picture_url = self ._extract_profile_picture (linkedin_id , api_resp )
104
+ profile_picture_url = self ._extract_profile_picture (
105
+ linkedin_id , api_resp )
100
106
return profile_picture_url
101
107
102
108
def get_profile_info (self , link : str ) -> dict :
0 commit comments