Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,56 @@ async def linkedin_post_details(post_id: Optional[str] = None, url: Optional[str
|
|
121 |
# }
|
122 |
|
123 |
|
124 |
-
@app.get("/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
async def fb_post_detail(username: Optional[str] = None, post_id: Optional[str] = None, url: Optional[str] = None):
|
126 |
if not url:
|
127 |
url = f"https://www.facebook.com/{username}/posts/{post_id}"
|
|
|
121 |
# }
|
122 |
|
123 |
|
124 |
+
@app.get("/instagram_post_details")
|
125 |
+
async def ig_post_detail(post_id: Optional[str] = None, url: Optional[str] = None):
|
126 |
+
if not url:
|
127 |
+
url = f"https://www.instagram.com/{post_id}"
|
128 |
+
|
129 |
+
res = requests.get(
|
130 |
+
url,
|
131 |
+
headers={
|
132 |
+
"user-agent": "Googlebot",
|
133 |
+
"accept-language": "en-US"
|
134 |
+
},
|
135 |
+
timeout=(10, 27),
|
136 |
+
)
|
137 |
+
|
138 |
+
soup = BeautifulSoup(res.content, "html.parser")
|
139 |
+
|
140 |
+
meta = soup.find("meta", {"name": "description"})
|
141 |
+
content = meta.get("content")
|
142 |
+
like_split = content.split(" likes, ")
|
143 |
+
likes = like_split[0]
|
144 |
+
comment_split = like_split[1].split(" comments - ")
|
145 |
+
comments = comment_split[0]
|
146 |
+
author_split = comment_split[1].split(": "")
|
147 |
+
author_date = author_split[0].split(" on ")
|
148 |
+
username = author_date[0]
|
149 |
+
date = author_date[1].split(":")[0]
|
150 |
+
|
151 |
+
name_desc = (
|
152 |
+
soup.find("meta", {"property": "og:title"})
|
153 |
+
.get("content")
|
154 |
+
.split(" on Instagram: ", 1)
|
155 |
+
)
|
156 |
+
full_name = name_desc[0]
|
157 |
+
desc = name_desc[-1]
|
158 |
+
|
159 |
+
return {
|
160 |
+
"insights": {
|
161 |
+
"likeCount": likes,
|
162 |
+
"commentCount": comments,
|
163 |
+
"shareCount": None,
|
164 |
+
},
|
165 |
+
"description": desc,
|
166 |
+
"username": username,
|
167 |
+
"full_name": full_name,
|
168 |
+
"username": username,
|
169 |
+
"date": date,
|
170 |
+
}
|
171 |
+
|
172 |
+
|
173 |
+
@app.get("/facebook_post_details")
|
174 |
async def fb_post_detail(username: Optional[str] = None, post_id: Optional[str] = None, url: Optional[str] = None):
|
175 |
if not url:
|
176 |
url = f"https://www.facebook.com/{username}/posts/{post_id}"
|