Skip to content

Commit 3c8dc97

Browse files
Merge pull request #2473 from avinashkranjan/deepsource-transform-f25344c0
format code with autopep8
2 parents fe0dcde + e14fda3 commit 3c8dc97

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

LinkedIn_Profile_Info/google_API.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
logger = logging.getLogger(__name__)
77

8+
89
class GoogleSearchAPI:
910
def __init__(self, key: str, cx: str):
1011
self._cx = cx
@@ -34,12 +35,14 @@ def _hit_api(self, linkedin_id: str) -> list:
3435
params["start"] = next_page[0]["startIndex"]
3536
elif resp.status_code == 429: # API rate limiting
3637
retry_after = int(resp.headers.get("Retry-After", 5))
37-
logger.warning(f"Google Custom Search API rate limit reached. Retrying in {retry_after} seconds.")
38+
logger.warning(
39+
f"Google Custom Search API rate limit reached. Retrying in {retry_after} seconds.")
3840
time.sleep(retry_after)
3941
else:
4042
resp.raise_for_status() # Raise an exception for other HTTP status codes
4143
except requests.exceptions.RequestException as e:
4244
logger.exception(f"Error in _hit_api: {e}")
4345
except Exception as e:
44-
logger.exception("An error occurred while processing the API response.")
46+
logger.exception(
47+
"An error occurred while processing the API response.")
4548
return results

LinkedIn_Profile_Info/profile.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
logger = logging.getLogger(__name__)
77

8+
89
class GoogleSearchAPI:
910
def __init__(self, key: str, cx: str):
1011
self._cx = cx
@@ -24,7 +25,8 @@ def _hit_api(self, linkedin_id: str) -> list:
2425
while True:
2526
resp = requests.get(self._api_url, params=params)
2627
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}")
2830
break
2931

3032
data = resp.json()
@@ -39,6 +41,7 @@ def _hit_api(self, linkedin_id: str) -> list:
3941
logger.exception("Error in _hit_api:")
4042
return results
4143

44+
4245
class ProfilePicture:
4346
def __init__(self, key: str, cx: str):
4447
self._api_obj = GoogleSearchAPI(key, cx)
@@ -54,7 +57,8 @@ def extract_id(self, link: str) -> str:
5457
return linkedin_id
5558

5659
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)
5862
return bool(match)
5963

6064
def _check_url_exists(self, link: str) -> bool:
@@ -71,7 +75,8 @@ def _extract_profile_picture(self, linkedin_id: str, res: list) -> str:
7175
search_id = self.extract_id(linkedin_url)
7276
if search_id == linkedin_id:
7377
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]
7580

7681
for url in metatags:
7782
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:
96101
def get_profile_picture(self, link: str) -> str:
97102
linkedin_id = self.extract_id(link)
98103
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)
100106
return profile_picture_url
101107

102108
def get_profile_info(self, link: str) -> dict:

0 commit comments

Comments
 (0)