Temporary redirect for failing links due to API ratelimiting

This commit is contained in:
Dylan 2022-06-02 01:09:04 +01:00
parent f0f709f62e
commit e64dee9349
2 changed files with 6 additions and 4 deletions

1
msgs.py Normal file
View file

@ -0,0 +1 @@
failedToScan="Failed to scan your link! This may be due to an incorrect link, private account, or the twitter API itself might be having issues (Check here: https://api.twitterstat.us/)\nIt's also possible that Twitter is API limiting me, in which case I can't do anything about it."

View file

@ -14,6 +14,7 @@ import urllib.request
import combineImg import combineImg
from datetime import date,datetime, timedelta from datetime import date,datetime, timedelta
from io import BytesIO from io import BytesIO
import msgs
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
@ -258,7 +259,7 @@ def direct_video(video_link): # Just get a redirect to a MP4 link from any tweet
print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url']) print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url'])
except Exception as e: except Exception as e:
print(e) print(e)
return message("Failed to scan your link! This may be due to an incorrect link, private account, or the twitter API itself might be having issues (Check here: https://api.twitterstat.us/)") return message(msgs.failedToScan)
else: else:
return redirect(cached_vnf['url'], 301) return redirect(cached_vnf['url'], 301)
print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url']) print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url'])
@ -273,7 +274,7 @@ def direct_video_link(video_link): # Just get a redirect to a MP4 link from any
print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url']) print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url'])
except Exception as e: except Exception as e:
print(e) print(e)
return message("Failed to scan your link! This may be due to an incorrect link, private account, or the twitter API itself might be having issues (Check here: https://api.twitterstat.us/)") return message(msgs.failedToScan)
else: else:
return cached_vnf['url'] return cached_vnf['url']
print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url']) print(" ➤ [ D ] Redirecting to direct URL: " + vnf['url'])
@ -289,7 +290,7 @@ def embed_video(video_link, image=0): # Return Embed from any tweet link
except Exception as e: except Exception as e:
print(e) print(e)
return message("Failed to scan your link! This may be due to an incorrect link, private account, or the twitter API itself might be having issues (Check here: https://api.twitterstat.us/)") return redirect(video_link) #message(msgs)
else: else:
return embed(video_link, cached_vnf, image) return embed(video_link, cached_vnf, image)
@ -543,7 +544,7 @@ def embedCombined(video_link):
except Exception as e: except Exception as e:
print(e) print(e)
return message("Failed to scan your link! This may be due to an incorrect link, private account, or the twitter API itself might be having issues (Check here: https://api.twitterstat.us/)") return message(msgs.failedToScan)
else: else:
return embedCombinedVnf(video_link, cached_vnf) return embedCombinedVnf(video_link, cached_vnf)