add parser for retweet for weibo, fix #44

This commit is contained in:
felinae98 2022-05-06 00:59:15 +08:00
parent d2098cf2c3
commit 47eb826e82
No known key found for this signature in database
GPG Key ID: 00C8B010587FF610

View File

@ -123,7 +123,11 @@ class Weibo(NewMessage):
"Mobile Safari/537.36", "Mobile Safari/537.36",
} }
info = raw_post["mblog"] info = raw_post["mblog"]
if info["isLongText"] or info["pic_num"] > 9: retweeted = False
if info.get("retweeted_status"):
retweeted = True
pic_num = info["retweeted_status"]["pic_num"] if retweeted else info["pic_num"]
if info["isLongText"] or pic_num > 9:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
res = await client.get( res = await client.get(
"https://m.weibo.cn/detail/{}".format(info["mid"]), headers=header "https://m.weibo.cn/detail/{}".format(info["mid"]), headers=header
@ -140,7 +144,12 @@ class Weibo(NewMessage):
) )
) )
parsed_text = self._get_text(info["text"]) parsed_text = self._get_text(info["text"])
pic_urls = [img["large"]["url"] for img in info.get("pics", [])] raw_pics_list = (
info["retweeted_status"].get("pics", [])
if retweeted
else info.get("pics", [])
)
pic_urls = [img["large"]["url"] for img in raw_pics_list]
detail_url = "https://weibo.com/{}/{}".format(info["user"]["id"], info["bid"]) detail_url = "https://weibo.com/{}/{}".format(info["user"]["id"], info["bid"])
# return parsed_text, detail_url, pic_urls # return parsed_text, detail_url, pic_urls
return Post( return Post(