jonathanjordan21 commited on
Commit
1ecee5c
·
verified ·
1 Parent(s): 4d674ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -21,6 +21,43 @@ app.add_middleware(
21
  allow_headers=["*"],
22
  )
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  @app.get("/google_search")
26
  async def google_search(q: str, delimiter: str = "\n---\n", sites: Annotated[list[str] | None, Query()] = None):
@@ -46,7 +83,7 @@ async def google_search(q: str, delimiter: str = "\n---\n", sites: Annotated[lis
46
  return {"results":texts}
47
 
48
 
49
- @app.get("/tiktok_details")
50
  async def read_item(username: str, video_id:str):
51
  user_agent = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36"
52
  # user_agent = "Googlebot/2.1"
 
21
  allow_headers=["*"],
22
  )
23
 
24
+ @app.get("/linkedin_post_details")
25
+ async def linkedin_post_details(post_id: str):
26
+ url = "https://www.linkedin.com/posts/"+post_id
27
+ res = requests.get(url)
28
+
29
+ text_maker = html2text.HTML2Text()
30
+ text_maker.ignore_links = True
31
+ text_maker.ignore_images = True
32
+ text_maker.bypass_tables = False
33
+
34
+ docs = text_maker.handle(res.content.decode("utf-8"))
35
+
36
+ chunks = docs.split("\n\n#")
37
+ linkedin_content = chunks[1]
38
+ user = linkedin_content.split("\n\n", 5)
39
+ full_name = user[1]
40
+ bio = user[2]
41
+ try:
42
+ date, edited = user[3].split(" ")
43
+ edited = True
44
+ except:
45
+ date = user[3].strip()
46
+ edited = False
47
+ content = "\n\n".join(user[5:])
48
+
49
+ insights = chunks[3].split("\n\n")[2]
50
+ likes = insights.split(" ", 1)[0].strip()
51
+ comments = insights.rsplit(" ", 2)[1].strip()
52
+
53
+ return {
54
+ "user": {"name": full_name, "bio": bio},
55
+ "content": content,
56
+ "date": date,
57
+ "is_edited": edited,
58
+ "insights": {"likeCount": likes, "commentCount": comments, "shareCount": None},
59
+ }
60
+
61
 
62
  @app.get("/google_search")
63
  async def google_search(q: str, delimiter: str = "\n---\n", sites: Annotated[list[str] | None, Query()] = None):
 
83
  return {"results":texts}
84
 
85
 
86
+ @app.get("/tiktok_video_details")
87
  async def read_item(username: str, video_id:str):
88
  user_agent = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36"
89
  # user_agent = "Googlebot/2.1"