Commit cb5175d
Changed files (1)
src
preview
src/preview/twitter.py
@@ -75,7 +75,6 @@ async def preview_twitter(
succ = True
except Exception as e:
logger.warning(f"Twitter API [tikhub] failed: {e}")
-
if not succ and "fxtwitter" in twitter_provider: # try fxtwitter
try:
this_info = await get_tweet_info_via_fxtwitter(url=url)
@@ -333,15 +332,15 @@ async def get_tweet_info_via_fxtwitter(url: str = "", handle: str = "", post_id:
url: https://x.com/{handle}/status/{post_id}
"""
- if not handle or not post_id:
- handle = url.split("/")[-3]
- post_id = url.split("/")[-1]
data = {}
if quote_info:
data = copy.deepcopy(quote_info)
handle = glom(data, "author.name", default="")
post_id = data.get("id", "")
else:
+ if not handle or not post_id:
+ handle = url.split("/")[-3]
+ post_id = url.split("/")[-1]
api_url = f"{API.FXTWITTER}/{handle}/status/{post_id}"
logger.info(f"Twitter preview via fxtwitter: {api_url}")
headers = {"user-agent": TELEGRAM_UA}
@@ -382,7 +381,7 @@ async def get_tweet_info_via_fxtwitter(url: str = "", handle: str = "", post_id:
info["replying_post_id"] = data.get("replying_to_status", "")
info["quote_info"] = data.get("quote", {})
info["has_master"] = bool(data.get("replying_to"))
- info["has_quote"] = bool(data.get("quote_info"))
+ info["has_quote"] = bool(info["quote_info"])
return info
@@ -392,15 +391,15 @@ async def get_tweet_info_via_vxtwitter(url: str = "", handle: str = "", post_id:
url: https://x.com/{handle}/status/{post_id}
"""
- if not handle or not post_id:
- handle = url.split("/")[-3]
- post_id = url.split("/")[-1]
data = {}
if quote_info:
data = copy.deepcopy(quote_info)
handle = data.get("user_screen_name", "")
post_id = data.get("tweetID", "")
else:
+ if not handle or not post_id:
+ handle = url.split("/")[-3]
+ post_id = url.split("/")[-1]
api_url = f"{API.VXTWITTER}/Twitter/status/{post_id}"
logger.info(f"Twitter preview via vxtwitter: {api_url}")
headers = {"user-agent": TELEGRAM_UA}