Fix issue with trimming text

This commit is contained in:
Dylan 2022-10-03 13:29:20 +01:00
parent 3999dbd4a1
commit 7ed13c3042
2 changed files with 17 additions and 8 deletions

13
msgs.py
View File

@ -26,17 +26,24 @@ def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
if pollDisplay==None:
pollDisplay=""
if qrt!={} and not (type=="" or type=="Video"):
qrtDisplay=genQrtDisplay(qrt)
if 'id' in qrt and ('https://twitter.com/'+qrt['screen_name']+'/status/'+qrt['id']) in body:
body = body.replace(('https://twitter.com/'+qrt['screen_name']+'/status/'+qrt['id']),"")
body = body.strip()
body+=qrtDisplay
qrt={}
if type=="" or type=="Video":
output = body+pollDisplay
elif qrt=={}:
output= body+pollDisplay+likesDisplay
else:
qrtDisplay = genQrtDisplay(qrt)
output= body + qrtDisplay + likesDisplay
output= body + likesDisplay
if len(output)>248:
# find out how many characters we need to remove
diff = len(output)-248
print("diff: "+str(diff))
# remove the characters from body, add ellipsis
body = body[:-(diff+1)]+""
return formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay)

View File

@ -314,6 +314,7 @@ def link_to_vnf_from_tweet_data(tweet,video_link):
qrt['handle'] = tweet['quoted_status']['user']['name']
qrt['screen_name'] = tweet['quoted_status']['user']['screen_name']
qrt['verified'] = tweet['quoted_status']['user']['verified']
qrt['id'] = tweet['quoted_status']['id_str']
text = tweet['full_text']
@ -420,7 +421,6 @@ def embed(video_link, vnf, image):
desc=msgs.formatEmbedDesc(vnf['type'],desc,vnf['qrt'],pollDisplay,likeDisplay)
print(len(desc))
appNamePost = ""
if vnf['type'] == "Text": # Change the template based on tweet type
template = 'text.html'
@ -463,12 +463,14 @@ def embedCombinedVnf(video_link,vnf):
urlLink = urllib.parse.quote(video_link)
likeDisplay = msgs.genLikesDisplay(vnf)
if vnf['qrt'] == {}: # Check if this is a QRT and modify the description
desc = (desc + likeDisplay)
if 'poll' in vnf:
pollDisplay= msgs.genPollDisplay(vnf['poll'])
else:
qrtDisplay=msgs.genQrtDisplay(vnf["qrt"])
desc = (desc + qrtDisplay + likeDisplay)
pollDisplay=""
desc=msgs.formatEmbedDesc(vnf['type'],desc,vnf['qrt'],pollDisplay,likeDisplay)
image = "https://vxtwitter.com/rendercombined.jpg?imgs="
for i in range(0,int(vnf['images'][4])):
image = image + vnf['images'][i] + ","