Add support for article previews, fixes #200

This commit is contained in:
Dylan
2024-09-16 00:15:07 +01:00
parent 93960b39da
commit 8e17044ecd
3 changed files with 48 additions and 12 deletions

View File

@ -14,6 +14,7 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
hashtags=[]
communityNote=None
oldTweetVersion = False
tweetArticle=None
#editedTweet=False
try:
if "birdwatch_pivot" in tweet:
@ -96,6 +97,20 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
media.append(vidUrl)
media_extended.append({"url":vidUrl,"type":"video","size":{"width":width,"height":height}})
if "article" in tweet:
try:
result = tweet["article"]["article_results"]["result"]
apiArticle = {
"title": result["title"],
"preview_text": result["preview_text"],
"image": None
}
if "cover_media" in result and "media_info" in result["cover_media"]:
apiArticle["image"] = result["cover_media"]["media_info"]["original_img_url"]
tweetArticle = apiArticle
except:
pass
#include_txt = request.args.get("include_txt", "false")
#include_rtf = request.args.get("include_rtf", "false") # for certain types of archival software (i.e Hydrus)
@ -199,6 +214,7 @@ def getApiResponse(tweet,include_txt=False,include_rtf=False):
"hasMedia": len(media) > 0,
"combinedMediaUrl": combinedMediaUrl,
"pollData": pollData,
"article": tweetArticle,
}
try:
apiObject["date_epoch"] = int(datetime.strptime(tweetL["created_at"], "%a %b %d %H:%M:%S %z %Y").timestamp())