diff --git a/msgs.py b/msgs.py index 370ebd8..8bcd17c 100644 --- a/msgs.py +++ b/msgs.py @@ -8,12 +8,13 @@ tweetSuspended="This Tweet is from a suspended account." videoDescLimit=220 tweetDescLimit=340 +providerLimit=220 def genLikesDisplay(vnf): if vnf['retweets'] > 0: - return ("\n\nšŸ’– " + numerize.numerize(vnf['likes']) + " šŸ” " + numerize.numerize(vnf['retweets'])) + return ("šŸ’– " + numerize.numerize(vnf['likes']) + " šŸ” " + numerize.numerize(vnf['retweets'])) else: - return ("\n\nšŸ’– " + numerize.numerize(vnf['likes'])) + return ("šŸ’– " + numerize.numerize(vnf['likes'])) def genQrtDisplay(qrt): verifiedCheck = "ā˜‘ļø" if ('verified' in qrt and qrt['verified']) else "" @@ -26,7 +27,18 @@ def genPollDisplay(poll): output+=choice["name"]+"\n"+("ā–ˆ"*int(choice["percent"]/pctSplit)) +" "+str(choice["percent"])+"%\n" return output -def formatEmbedDesc(type,body,qrt,pollData,likesDisplay): +# formats the top text of the embed +def formatProvider(base,vnf): + finalText = base + likes = genLikesDisplay(vnf) + finalText += "\n" + likes + if ('communityNote' in vnf and vnf['communityNote'] != None): + finalText += "\nāš ļø Has community note" + if len(finalText) > providerLimit: + finalText = base + return finalText + +def formatEmbedDesc(type,body,qrt,pollData): # Trim the embed description to 248 characters, prioritizing poll and likes qrtType=None @@ -51,16 +63,16 @@ def formatEmbedDesc(type,body,qrt,pollData,likesDisplay): qrt=None if type=="" or type=="Video": - output = body+pollDisplay+likesDisplay + output = body+pollDisplay elif qrt==None: - output= body+pollDisplay+likesDisplay + output= body+pollDisplay else: - output= body + likesDisplay + output= body if len(output)>limit: # find out how many characters we need to remove diff = len(output)-limit # remove the characters from body, add ellipsis body = body[:-(diff+1)]+"…" - return formatEmbedDesc(type,body,qrt,pollData,likesDisplay) + return formatEmbedDesc(type,body,qrt,pollData) else: return output diff --git a/templates/image.html b/templates/image.html index 122bf09..344aba5 100644 --- a/templates/image.html +++ b/templates/image.html @@ -23,5 +23,5 @@ - + {% endblock %} {% block body %} Redirecting you to the tweet in a moment. Or click here. {% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html deleted file mode 100644 index e4bf911..0000000 --- a/templates/index.html +++ /dev/null @@ -1,30 +0,0 @@ -{% extends 'base.html' %} {% block head %} - - - - - - - - - - - - - - - - - - - - - - - - - - - {% endblock %} {% block body %} Redirecting you to the tweet in a moment. Or click here. {% endblock %} \ No newline at end of file diff --git a/templates/text.html b/templates/text.html index e9dbcae..3073656 100644 --- a/templates/text.html +++ b/templates/text.html @@ -9,5 +9,5 @@ - + {% endblock %} {% block body %} Redirecting you to the tweet in a moment. Or click here. {% endblock %} \ No newline at end of file diff --git a/templates/video.html b/templates/video.html index 77a7225..ff2ddef 100644 --- a/templates/video.html +++ b/templates/video.html @@ -18,5 +18,5 @@ - + {% endblock %} {% block body %} Redirecting you to the tweet in a moment. Or click here.{% endblock %} \ No newline at end of file diff --git a/twitfix.py b/twitfix.py index fbbcc6b..9a82535 100644 --- a/twitfix.py +++ b/twitfix.py @@ -76,7 +76,7 @@ def message(text): def renderImageTweetEmbed(tweetData,image,appnameSuffix=""): qrt = tweetData['qrt'] - embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData)) + embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,tweetData['pollData']) if image.startswith("https://pbs.twimg.com") and "?" not in image: image = f"{image}?name=orig" @@ -88,12 +88,12 @@ def renderImageTweetEmbed(tweetData,image,appnameSuffix=""): desc=embedDesc, urlEncodedDesc=urllib.parse.quote(embedDesc), tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}', - appname=config['config']['appname']+appnameSuffix, + appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData), ) def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""): qrt = tweetData['qrt'] - embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData)) + embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,tweetData['pollData']) mediaInfo=fixMedia(mediaInfo) return render_template("video.html", @@ -103,19 +103,19 @@ def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""): desc=embedDesc, urlEncodedDesc=urllib.parse.quote(embedDesc), tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}', - appname=config['config']['appname']+appnameSuffix, + appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData), ) def renderTextTweetEmbed(tweetData,appnameSuffix=""): qrt = tweetData['qrt'] - embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData)) + embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,tweetData['pollData']) return render_template("text.html", tweet=tweetData, host=config['config']['url'], desc=embedDesc, urlEncodedDesc=urllib.parse.quote(embedDesc), tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}', - appname=config['config']['appname']+appnameSuffix, + appname=msgs.formatProvider(config['config']['appname']+appnameSuffix,tweetData), ) @app.route('/robots.txt')