Skip to content

Commit 687b89b

Browse files
committed
Add get_socials method that extracts links to social media accounts
1 parent ddecb2f commit 687b89b

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

loading_sdk/sync_api/client.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,7 @@ def get_about(self):
467467
if not data:
468468
return {"code": 404, "message": "No data found", "data": None}
469469

470-
data = {
471-
"code": 200,
472-
"message": "OK",
473-
"data": data,
474-
}
475-
476-
return data
470+
return {"code": 200, "message": "OK", "data": data}
477471

478472
def get_socials(self):
479473
"""Get social media links
@@ -483,4 +477,7 @@ def get_socials(self):
483477

484478
data = extract_data("socials")
485479

486-
return data
480+
if not data:
481+
return {"code": 404, "message": "No results found", "data": None}
482+
483+
return {"code": 200, "message": "OK", "data": data}

loading_sdk/sync_api/extractors.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,24 @@ def get_data(self):
8080

8181
class SocialsExtractor(Extractor):
8282
def get_data(self):
83-
pass
83+
page_source = self.get_source(BASE_URL)
84+
main_script_url = self.get_script(page_source)
85+
main_script_source = self.get_source(f"{BASE_URL}/{main_script_url}")
86+
87+
match = re.findall(
88+
r"(?:href:\")"
89+
+ r"(https:\/\/|https:\/\/www.(.*?)\..*?\/.*?)"
90+
+ r"(?:\",target:\"_blank\",rel:\"noreferrer noopener\",className:)"
91+
+ r"(?:\"Footer-(?:icon|patreon)\")",
92+
main_script_source,
93+
)
94+
95+
if not match:
96+
return None
97+
98+
data = [{"name": social[1], "link": social[0]} for social in match]
99+
100+
return data
84101

85102

86103
class ExtractorFactory(ABC):

0 commit comments

Comments
 (0)