Increased description limit for tweets

This commit is contained in:
Dylan 2023-02-17 18:10:23 +00:00
parent ae6774f126
commit 3717430c3f
2 changed files with 12 additions and 2 deletions

View File

@ -3,6 +3,8 @@ failedToScanExtra = "\n\nTwitter gave me this error: "
tweetNotFound="Tweet not found."
tweetSuspended="This Tweet is from a suspended account."
tweetDescLimit=340
def genLikesDisplay(vnf):
return ("\n\n💖 " + str(vnf['likes']) + " 🔁 " + str(vnf['rts']))
@ -38,9 +40,9 @@ def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
output= body+pollDisplay+likesDisplay
else:
output= body + likesDisplay
if len(output)>248:
if len(output)>tweetDescLimit:
# find out how many characters we need to remove
diff = len(output)-248
diff = len(output)-tweetDescLimit
# remove the characters from body, add ellipsis
body = body[:-(diff+1)]+""
return formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay)

View File

@ -165,6 +165,14 @@ def test_embedFromCache():
resp = client.get(testMultiMediaTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
assert resp.status_code==200
def test_veryLongEmbed():
cache.clearCache()
cache.setCache({'https://twitter.com/TEST/status/1234':
{"description":"A"*1024,"hits":0,"images":["","","","",""],"likes":1234,"nsfw":False,"pfp":"","qrt":{},"rts":1234,"screen_name":"TEST","thumbnail":"","time":"","tweet":"https://twitter.com/TEST/status/1234","type":"Text","uploader":"Test","url":""}
})
resp = client.get('https://twitter.com/TEST/status/1234'.replace("https://twitter.com",""),headers={"User-Agent":"test"})
assert resp.status_code==200
def test_embedFromOutdatedCache(): # presets a cache that has VNF's with missing fields; there's probably a better way to do this
cache.setCache({"https://twitter.com/Twitter/status/1118295916874739714":{"description":"On profile pages, we used to only show someones replies, not the original Tweet 🙄 Now were showing both so you can follow the conversation more easily! https://t.co/LSBEZYFqmY","hits":0,"images":["https://pbs.twimg.com/media/D4TS4xeX4AA02DI.jpg","","","","1"],"likes":5033,"nsfw":False,"pfp":"http://pbs.twimg.com/profile_images/1488548719062654976/u6qfBBkF_normal.jpg","qrt":{},"rts":754,"screen_name":"Twitter","thumbnail":"https://pbs.twimg.com/media/D4TS4xeX4AA02DI.jpg","time":"Tue Apr 16 23:31:38 +0000 2019","tweet":"https://twitter.com/Twitter/status/1118295916874739714","type":"Image","uploader":"Twitter","url":""},
"https://twitter.com/Twitter/status/1263145271946551300":{"description":"Testing, testing...\n\nA new way to have a convo with exactly who you want. Were starting with a small % globally, so keep your 👀 out to see it in action. https://t.co/pV53mvjAVT","hits":0,"images":["","","","",""],"likes":61584,"nsfw":False,"pfp":"http://pbs.twimg.com/profile_images/1488548719062654976/u6qfBBkF_normal.jpg","qrt":{},"rts":17138,"screen_name":"Twitter","thumbnail":"http://pbs.twimg.com/media/EYeX7akWsAIP1_1.jpg","time":"Wed May 20 16:31:15 +0000 2020","tweet":"https://twitter.com/Twitter/status/1263145271946551300","type":"Video","uploader":"Twitter","url":"https://video.twimg.com/amplify_video/1263145212760805376/vid/1280x720/9jous8HM0_duxL0w.mp4?tag=13"},