More bugfixes
This commit is contained in:
parent
0858f6263b
commit
2d51ac1671
10
msgs.py
10
msgs.py
@ -22,11 +22,11 @@ def genQrtDisplay(qrt):
|
|||||||
def genPollDisplay(poll):
|
def genPollDisplay(poll):
|
||||||
pctSplit=10
|
pctSplit=10
|
||||||
output="\n\n"
|
output="\n\n"
|
||||||
for choice in poll["choices"]:
|
for choice in poll["options"]:
|
||||||
output+=choice["text"]+"\n"+("█"*int(choice["percent"]/pctSplit)) +" "+str(choice["percent"])+"%\n"
|
output+=choice["name"]+"\n"+("█"*int(choice["percent"]/pctSplit)) +" "+str(choice["percent"])+"%\n"
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
|
def formatEmbedDesc(type,body,qrt,pollData,likesDisplay):
|
||||||
# Trim the embed description to 248 characters, prioritizing poll and likes
|
# Trim the embed description to 248 characters, prioritizing poll and likes
|
||||||
|
|
||||||
qrtType=None
|
qrtType=None
|
||||||
@ -36,8 +36,10 @@ def formatEmbedDesc(type,body,qrt,pollDisplay,likesDisplay):
|
|||||||
limit = videoDescLimit if type=="Text" or type=="Video" or (qrt!=None and (qrtType=="Text" or qrtType=="Video")) else tweetDescLimit
|
limit = videoDescLimit if type=="Text" or type=="Video" or (qrt!=None and (qrtType=="Text" or qrtType=="Video")) else tweetDescLimit
|
||||||
|
|
||||||
output = ""
|
output = ""
|
||||||
if pollDisplay==None:
|
if pollData==None:
|
||||||
pollDisplay=""
|
pollDisplay=""
|
||||||
|
else:
|
||||||
|
pollDisplay=genPollDisplay(pollData)
|
||||||
|
|
||||||
if qrt!=None:
|
if qrt!=None:
|
||||||
|
|
||||||
|
@ -18,5 +18,5 @@
|
|||||||
<meta property="og:image" content="{{ media['thumbnail_url'] }}" />
|
<meta property="og:image" content="{{ media['thumbnail_url'] }}" />
|
||||||
<meta property="og:description" content="{{ desc }}" />
|
<meta property="og:description" content="{{ desc }}" />
|
||||||
|
|
||||||
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ desc }}&link={{ tweetLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
<link rel="alternate" href="{{ host }}/oembed.json?desc={{ urlUser }}&user={{ urlEncodedDesc }}&link={{ tweetLink }}&ttype=video&provider={{ appname }}" type="application/json+oembed" title="{{ tweet['user_name'] }}">
|
||||||
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
<meta http-equiv="refresh" content="0; url = {{ tweetLink }}" /> {% endblock %} {% block body %} Redirecting you to the tweet in a moment. <a href="{{ tweetLink }}">Or click here.</a> {% endblock %}
|
@ -159,3 +159,14 @@ def test_embed_mixedMedia():
|
|||||||
resp = client.get(testMixedMediaTweet.replace("https://twitter.com","")+"/2",headers={"User-Agent":"test"})
|
resp = client.get(testMixedMediaTweet.replace("https://twitter.com","")+"/2",headers={"User-Agent":"test"})
|
||||||
assert resp.status_code==200
|
assert resp.status_code==200
|
||||||
assert img1 not in str(resp.data) and img2 in str(resp.data)
|
assert img1 not in str(resp.data) and img2 in str(resp.data)
|
||||||
|
|
||||||
|
def test_embed_poll():
|
||||||
|
resp = client.get(testPollTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "Mean one thing" in str(resp.data)
|
||||||
|
assert "78.82%" in str(resp.data)
|
||||||
|
|
||||||
|
def test_embed_stripLastUrl():
|
||||||
|
resp = client.get(testMediaTweet.replace("https://twitter.com",""),headers={"User-Agent":"test"})
|
||||||
|
assert resp.status_code==200
|
||||||
|
assert "HgLAbiXw2E" not in str(resp.data)
|
15
twitfix.py
15
twitfix.py
@ -4,7 +4,8 @@ from flask_cors import CORS
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import combineImg
|
import combineImg
|
||||||
from io import BytesIO, StringIO
|
from io import BytesIO
|
||||||
|
import urllib
|
||||||
import msgs
|
import msgs
|
||||||
import twExtract as twExtract
|
import twExtract as twExtract
|
||||||
from configHandler import config
|
from configHandler import config
|
||||||
@ -54,38 +55,38 @@ def message(text):
|
|||||||
|
|
||||||
def renderImageTweetEmbed(tweetData,image,appnameSuffix=""):
|
def renderImageTweetEmbed(tweetData,image,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
pollData = None
|
embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
||||||
embedDesc = msgs.formatEmbedDesc("Image",tweetData['text'],qrt,pollData,msgs.genLikesDisplay(tweetData))
|
|
||||||
return render_template("image.html",
|
return render_template("image.html",
|
||||||
tweet=tweetData,
|
tweet=tweetData,
|
||||||
pic=[image],
|
pic=[image],
|
||||||
host=config['config']['url'],
|
host=config['config']['url'],
|
||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=config['config']['appname']+appnameSuffix,
|
||||||
)
|
)
|
||||||
|
|
||||||
def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""):
|
def renderVideoTweetEmbed(tweetData,mediaInfo,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
pollData = None
|
embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
||||||
embedDesc = msgs.formatEmbedDesc("Video",tweetData['text'],qrt,pollData,msgs.genLikesDisplay(tweetData))
|
|
||||||
return render_template("video.html",
|
return render_template("video.html",
|
||||||
tweet=tweetData,
|
tweet=tweetData,
|
||||||
media=mediaInfo,
|
media=mediaInfo,
|
||||||
host=config['config']['url'],
|
host=config['config']['url'],
|
||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=config['config']['appname']+appnameSuffix,
|
||||||
)
|
)
|
||||||
|
|
||||||
def renderTextTweetEmbed(tweetData,appnameSuffix=""):
|
def renderTextTweetEmbed(tweetData,appnameSuffix=""):
|
||||||
qrt = tweetData['qrt']
|
qrt = tweetData['qrt']
|
||||||
pollData = None
|
embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,tweetData['pollData'],msgs.genLikesDisplay(tweetData))
|
||||||
embedDesc = msgs.formatEmbedDesc("Text",tweetData['text'],qrt,pollData,msgs.genLikesDisplay(tweetData))
|
|
||||||
return render_template("text.html",
|
return render_template("text.html",
|
||||||
tweet=tweetData,
|
tweet=tweetData,
|
||||||
host=config['config']['url'],
|
host=config['config']['url'],
|
||||||
desc=embedDesc,
|
desc=embedDesc,
|
||||||
|
urlEncodedDesc=urllib.parse.quote(embedDesc),
|
||||||
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
tweetLink=f'https://twitter.com/{tweetData["user_screen_name"]}/status/{tweetData["tweetID"]}',
|
||||||
appname=config['config']['appname']+appnameSuffix,
|
appname=config['config']['appname']+appnameSuffix,
|
||||||
)
|
)
|
||||||
|
10
utils.py
10
utils.py
@ -1,7 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
pathregex = re.compile("\\w{1,15}\\/(status|statuses)\\/(\\d{2,20})")
|
pathregex = re.compile("\\w{1,15}\\/(status|statuses)\\/(\\d{2,20})")
|
||||||
|
endTCOregex = re.compile("(^.*?) +https:\/\/t.co\/.*?$")
|
||||||
|
|
||||||
def getTweetIdFromUrl(url):
|
def getTweetIdFromUrl(url):
|
||||||
match = pathregex.search(url)
|
match = pathregex.search(url)
|
||||||
@ -9,3 +9,11 @@ def getTweetIdFromUrl(url):
|
|||||||
return match.group(2)
|
return match.group(2)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def stripEndTCO(text):
|
||||||
|
# remove t.co links at the end of a string
|
||||||
|
match = endTCOregex.search(text)
|
||||||
|
if match is not None:
|
||||||
|
return match.group(1)
|
||||||
|
else:
|
||||||
|
return text
|
4
vxApi.py
4
vxApi.py
@ -1,6 +1,7 @@
|
|||||||
import html
|
import html
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from configHandler import config
|
from configHandler import config
|
||||||
|
from utils import stripEndTCO
|
||||||
|
|
||||||
def getApiResponse(tweet,include_txt=False,include_zip=False):
|
def getApiResponse(tweet,include_txt=False,include_zip=False):
|
||||||
tweetL = tweet["legacy"]
|
tweetL = tweet["legacy"]
|
||||||
@ -89,6 +90,7 @@ def getApiResponse(tweet,include_txt=False,include_zip=False):
|
|||||||
twText = twText.replace(eurl["url"], "")
|
twText = twText.replace(eurl["url"], "")
|
||||||
else:
|
else:
|
||||||
twText = twText.replace(eurl["url"],eurl["expanded_url"])
|
twText = twText.replace(eurl["url"],eurl["expanded_url"])
|
||||||
|
twText = stripEndTCO(twText)
|
||||||
|
|
||||||
# check if all extended media are the same type
|
# check if all extended media are the same type
|
||||||
sameMedia = False
|
sameMedia = False
|
||||||
@ -102,7 +104,7 @@ def getApiResponse(tweet,include_txt=False,include_zip=False):
|
|||||||
sameMedia = True
|
sameMedia = True
|
||||||
|
|
||||||
combinedMediaUrl = None
|
combinedMediaUrl = None
|
||||||
if sameMedia and media_extended[0]["type"] == "image" and len(media) > 1:
|
if len(media_extended) > 0 and sameMedia and media_extended[0]["type"] == "image" and len(media) > 1:
|
||||||
host=config['config']['url']
|
host=config['config']['url']
|
||||||
combinedMediaUrl = f'{host}/rendercombined.jpg?imgs='
|
combinedMediaUrl = f'{host}/rendercombined.jpg?imgs='
|
||||||
for i in media:
|
for i in media:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user