From 7bbcd75600ef1301ea217c78f54c8653b0f54a71 Mon Sep 17 00:00:00 2001 From: adryd Date: Tue, 3 May 2022 10:37:15 -0400 Subject: [PATCH] Fix tweet text content appearing in telegram - Fix video quality sorting - Fix screenName being empty - Fix img accessed before declaration - Hopefully tweet text content shows now in telegram - Add flask_cors dependency - Remove unnecesary react-helmet garbage --- requirements.txt | 1 + templates/default.html | 2 +- templates/image.html | 2 +- templates/index.html | 8 ++++---- templates/text.html | 2 +- templates/video.html | 4 ++-- twitfix.py | 12 +++++------- wsgi.py | 3 ++- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/requirements.txt b/requirements.txt index bfaec99..77eea09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Flask youtube_dl pymongo twitter +flask_cors \ No newline at end of file diff --git a/templates/default.html b/templates/default.html index 4c86f4d..e58926e 100644 --- a/templates/default.html +++ b/templates/default.html @@ -5,7 +5,7 @@ - + {% endblock %} diff --git a/templates/image.html b/templates/image.html index 97c3ddf..d75a01d 100644 --- a/templates/image.html +++ b/templates/image.html @@ -15,7 +15,7 @@ --> {% block head %} - + diff --git a/templates/index.html b/templates/index.html index 607cbc3..934c3dc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -2,7 +2,7 @@ {% block head %} - + @@ -15,7 +15,6 @@ - @@ -23,10 +22,11 @@ - - + + + diff --git a/templates/text.html b/templates/text.html index 892e2d6..95ea95d 100644 --- a/templates/text.html +++ b/templates/text.html @@ -19,7 +19,7 @@ --> {% block head %} - + diff --git a/templates/video.html b/templates/video.html index 511e54c..0c6300d 100644 --- a/templates/video.html +++ b/templates/video.html @@ -2,7 +2,7 @@ {% block head %} - + @@ -19,8 +19,8 @@ - + diff --git a/twitfix.py b/twitfix.py index 94fd17b..7e35fd6 100644 --- a/twitfix.py +++ b/twitfix.py @@ -387,9 +387,9 @@ def tweetInfo(url, tweet="", desc="", thumb="", uploader="", screen_name="", pfp def link_to_vnf_from_api(video_link): print(" ➤ [ + ] Attempting to download tweet info from Twitter API") + imgs = ["","","",""] # initialize this in this scope to not cause errors twid = int(re.sub(r'\?.*$','',video_link.rsplit("/", 1)[-1])) # gets the tweet ID as a int from the passed url tweet = twitter_api.statuses.show(_id=twid, tweet_mode="extended") - #print(tweet) print(" ➤ [ + ] Tweet Type: " + tweetType(tweet)) # Check to see if tweet has a video, if not, make the url passed to the VNF the first t.co link in the tweet if tweetType(tweet) == "Video": @@ -397,13 +397,12 @@ def link_to_vnf_from_api(video_link): best_bitrate = 0 thumb = tweet['extended_entities']['media'][0]['media_url'] for video in tweet['extended_entities']['media'][0]['video_info']['variants']: - if video.content_type == "video/mp4" and video.bitrate > best_bitrate: - url = video.url + if video['content_type'] == "video/mp4" and video['bitrate'] > best_bitrate: + url = video['url'] elif tweetType(tweet) == "Text": url = "" thumb = "" else: - imgs = ["","","",""] i = 0 for media in tweet['extended_entities']['media']: imgs[i] = media['media_url_https'] @@ -412,7 +411,6 @@ def link_to_vnf_from_api(video_link): #print(imgs) url = "" - images= imgs thumb = tweet['extended_entities']['media'][0]['media_url_https'] qrt = {} @@ -420,7 +418,7 @@ def link_to_vnf_from_api(video_link): if 'quoted_status' in tweet: qrt['desc'] = tweet['quoted_status']['full_text'] qrt['handle'] = tweet['quoted_status']['user']['name'] - qrt['screenname'] = tweet['quoted_status']['user']['screen_name'] + qrt['screen_name'] = tweet['quoted_status']['user']['screen_name'] text = tweet['full_text'] @@ -525,7 +523,7 @@ def embed(video_link, vnf, image): elif vnf['qrt'] == {}: # Check if this is a QRT and modify the description desc = (desc + likeDisplay) else: - qrtDisplay = ("\n─────────────\n ➤ QRT of " + vnf['qrt']['handle'] + " (@" + vnf['qrt']['screenname'] + "):\n─────────────\n'" + vnf['qrt']['desc'] + "'") + qrtDisplay = ("\n─────────────\n ➤ QRT of " + vnf['qrt']['handle'] + " (@" + vnf['qrt']['screen_name'] + "):\n─────────────\n'" + vnf['qrt']['desc'] + "'") desc = (desc + qrtDisplay + likeDisplay) except: vnf['likes'] = 0; vnf['rts'] = 0; vnf['time'] = 0 diff --git a/wsgi.py b/wsgi.py index ed31819..456d4ba 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,4 +1,5 @@ from twitfix import app if __name__ == "__main__": - app.run() \ No newline at end of file + # listen on 0.0.0.0 to facilitate testing with real services + app.run(host='0.0.0.0') \ No newline at end of file