Fix text trimming with images and text posts
This commit is contained in:
parent
c6840ad093
commit
c395c00a11
8
msgs.py
8
msgs.py
@ -3,6 +3,7 @@ failedToScanExtra = "\n\nTwitter gave me this error: "
|
|||||||
tweetNotFound="Tweet not found."
|
tweetNotFound="Tweet not found."
|
||||||
tweetSuspended="This Tweet is from a suspended account."
|
tweetSuspended="This Tweet is from a suspended account."
|
||||||
|
|
||||||
|
videoDescLimit=220
|
||||||
tweetDescLimit=340
|
tweetDescLimit=340
|
||||||
|
|
||||||
def genLikesDisplay(vnf):
|
def genLikesDisplay(vnf):
|
||||||
@ -21,6 +22,9 @@ def genPollDisplay(poll):
|
|||||||
|
|
||||||
def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
|
def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
|
||||||
# Trim the embed description to 248 characters, prioritizing poll and likes
|
# Trim the embed description to 248 characters, prioritizing poll and likes
|
||||||
|
|
||||||
|
limit = videoDescLimit if type=="" or type=="Video" else tweetDescLimit
|
||||||
|
|
||||||
output = ""
|
output = ""
|
||||||
if pollDisplay==None:
|
if pollDisplay==None:
|
||||||
pollDisplay=""
|
pollDisplay=""
|
||||||
@ -40,9 +44,9 @@ def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
|
|||||||
output= body+pollDisplay+likesDisplay
|
output= body+pollDisplay+likesDisplay
|
||||||
else:
|
else:
|
||||||
output= body + likesDisplay
|
output= body + likesDisplay
|
||||||
if len(output)>tweetDescLimit:
|
if len(output)>limit:
|
||||||
# find out how many characters we need to remove
|
# find out how many characters we need to remove
|
||||||
diff = len(output)-tweetDescLimit
|
diff = len(output)-limit
|
||||||
# remove the characters from body, add ellipsis
|
# remove the characters from body, add ellipsis
|
||||||
body = body[:-(diff+1)]+"…"
|
body = body[:-(diff+1)]+"…"
|
||||||
return formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay)
|
return formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay)
|
||||||
|
@ -453,7 +453,7 @@ def embed(video_link, vnf, image):
|
|||||||
image = embedVNF['images'][image]
|
image = embedVNF['images'][image]
|
||||||
template = 'image.html'
|
template = 'image.html'
|
||||||
elif qrt['type'] == "Video" or qrt['type'] == "":
|
elif qrt['type'] == "Video" or qrt['type'] == "":
|
||||||
urlDesc = urllib.parse.quote(textwrap.shorten(desc, width=220, placeholder="..."))
|
urlDesc = urllib.parse.quote(desc)
|
||||||
template = 'video.html'
|
template = 'video.html'
|
||||||
|
|
||||||
if vnf['type'] == "Image":
|
if vnf['type'] == "Image":
|
||||||
@ -466,11 +466,11 @@ def embed(video_link, vnf, image):
|
|||||||
if vnf['isGif'] == True and config['config']['gifConvertAPI'] != "" and config['config']['gifConvertAPI'] != "none":
|
if vnf['isGif'] == True and config['config']['gifConvertAPI'] != "" and config['config']['gifConvertAPI'] != "none":
|
||||||
vnf['url'] = f"{config['config']['gifConvertAPI']}/convert.mp4?url={vnf['url']}"
|
vnf['url'] = f"{config['config']['gifConvertAPI']}/convert.mp4?url={vnf['url']}"
|
||||||
appNamePost = " - GIF"
|
appNamePost = " - GIF"
|
||||||
urlDesc = urllib.parse.quote(textwrap.shorten(desc, width=220, placeholder="..."))
|
urlDesc = urllib.parse.quote(desc)
|
||||||
template = 'video.html'
|
template = 'video.html'
|
||||||
|
|
||||||
if vnf['type'] == "":
|
if vnf['type'] == "":
|
||||||
urlDesc = urllib.parse.quote(textwrap.shorten(desc, width=220, placeholder="..."))
|
urlDesc = urllib.parse.quote(desc)
|
||||||
template = 'video.html'
|
template = 'video.html'
|
||||||
|
|
||||||
color = "#7FFFD4" # Green
|
color = "#7FFFD4" # Green
|
||||||
|
Loading…
x
Reference in New Issue
Block a user