jonathanjordan21 commited on
Commit
cce7a99
·
verified ·
1 Parent(s): 90df98b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -36
app.py CHANGED
@@ -90,51 +90,51 @@ async def tiktok_video_details(username: str, video_id:str):
90
  user_agent = "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
91
  res = requests.get(url, headers={"user-agent": user_agent})
92
 
93
- soup = BeautifulSoup(res.content, "html.parser")
94
 
95
- insights = soup.find("meta", {"property": "og:description"}).get("content")
96
- likes = insights.split(" ", 1)[0]
97
- desc = insights.rsplit(" comments. “", 1)[-1][:-1]
98
- comments = insights.split(", ", 1)[-1].split(" ", 1)[0]
99
 
100
- name = soup.find("meta", {"property": "og:title"}).get("content")[9:]
101
 
102
- return {
103
- "insights": {"likeCount": likes, "commentCount": comments, "shareCount":None, "viewCount":None},
104
- "description": desc,
105
- "username": username,
106
- "name": name,
107
- }
108
 
109
- # text_maker = html2text.HTML2Text()
110
- # text_maker.ignore_links = True
111
- # text_maker.ignore_images = True
112
- # text_maker.bypass_tables = False
113
 
114
- # print("RESPONSE DETAIlL", res.content.decode("utf-8"))
115
 
116
- # docs = text_maker.handle(res.content.decode("utf-8"))
117
 
118
- # print("DOCS", docs)
119
 
120
- # content_detail = docs.split("###")[5]
121
 
122
- # likes, comments, bookmarks, shares = re.findall(r'\*\*([\w.]+)\*\*', content_detail)
123
 
124
 
125
- # profile = [x.strip() for x in content_detail.split("\n\nSpeed\n\n", 1)[1].split("\n", 6) if x.strip()]
126
- # username = profile[0]
127
- # date = profile[1].rsplit(" · ", 1)[-1]
128
- # desc = profile[-1].replace("**", "")
129
 
130
- # return {
131
- # "insights":{
132
- # "likeCount":likes,
133
- # "commentCount":comments,
134
- # "bookmarkCount":bookmarks,
135
- # "shareCount":shares
136
- # },
137
- # "username":username,
138
- # "date":date,
139
- # "description":desc
140
- # }
 
90
  user_agent = "Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)"
91
  res = requests.get(url, headers={"user-agent": user_agent})
92
 
93
+ # soup = BeautifulSoup(res.content, "html.parser")
94
 
95
+ # insights = soup.find("meta", {"property": "og:description"}).get("content")
96
+ # likes = insights.split(" ", 1)[0]
97
+ # desc = insights.rsplit(" comments. “", 1)[-1][:-1]
98
+ # comments = insights.split(", ", 1)[-1].split(" ", 1)[0]
99
 
100
+ # name = soup.find("meta", {"property": "og:title"}).get("content")[9:]
101
 
102
+ # return {
103
+ # "insights": {"likeCount": likes, "commentCount": comments, "shareCount":None, "viewCount":None},
104
+ # "description": desc,
105
+ # "username": username,
106
+ # "name": name,
107
+ # }
108
 
109
+ text_maker = html2text.HTML2Text()
110
+ text_maker.ignore_links = True
111
+ text_maker.ignore_images = True
112
+ text_maker.bypass_tables = False
113
 
114
+ print("RESPONSE DETAIlL", res.content.decode("utf-8"))
115
 
116
+ docs = text_maker.handle(res.content.decode("utf-8"))
117
 
118
+ print("DOCS", docs)
119
 
120
+ content_detail = docs.split("###")[5]
121
 
122
+ likes, comments, bookmarks, shares = re.findall(r'\*\*([\w.]+)\*\*', content_detail)
123
 
124
 
125
+ profile = [x.strip() for x in content_detail.split("\n\nSpeed\n\n", 1)[1].split("\n", 6) if x.strip()]
126
+ username = profile[0]
127
+ date = profile[1].rsplit(" · ", 1)[-1]
128
+ desc = profile[-1].replace("**", "")
129
 
130
+ return {
131
+ "insights":{
132
+ "likeCount":likes,
133
+ "commentCount":comments,
134
+ "bookmarkCount":bookmarks,
135
+ "shareCount":shares
136
+ },
137
+ "username":username,
138
+ "date":date,
139
+ "description":desc
140
+ }