API Mirror
This commit is contained in:
parent
c58e9b2755
commit
1954a72bd0
9
twExtract/Dockerfile
Normal file
9
twExtract/Dockerfile
Normal file
@ -0,0 +1,9 @@
|
||||
FROM public.ecr.aws/lambda/python:3.8
|
||||
RUN pip install yt-dlp
|
||||
|
||||
|
||||
# Copy function code
|
||||
COPY __init__.py ${LAMBDA_TASK_ROOT}/app.py
|
||||
|
||||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
|
||||
CMD [ "app.lambda_handler" ]
|
@ -1,4 +1,3 @@
|
||||
import imp
|
||||
import yt_dlp
|
||||
from yt_dlp.extractor import twitter
|
||||
import json
|
||||
@ -15,4 +14,16 @@ def extractStatus(url):
|
||||
'include_user_entities': 0,
|
||||
'tweet_mode': 'extended',
|
||||
})
|
||||
return status
|
||||
return status
|
||||
|
||||
def lambda_handler(event, context):
|
||||
if ("queryStringParameters" not in event):
|
||||
return {
|
||||
"statusCode": 400,
|
||||
"body": "Invalid request."
|
||||
}
|
||||
url = event["queryStringParameters"].get("url","")
|
||||
return {
|
||||
'statusCode': 200,
|
||||
'body': extractStatus(url)
|
||||
}
|
14
twitfix.py
14
twitfix.py
@ -1,3 +1,4 @@
|
||||
from random import Random, random
|
||||
from weakref import finalize
|
||||
from flask import Flask, render_template, request, redirect, abort, Response, send_from_directory, url_for, send_file, make_response, jsonify
|
||||
from flask_cors import CORS
|
||||
@ -13,10 +14,10 @@ import combineImg
|
||||
from datetime import date,datetime, timedelta
|
||||
from io import BytesIO
|
||||
import msgs
|
||||
import twExtract
|
||||
import twExtract as twExtract
|
||||
from configHandler import config
|
||||
from cache import addVnfToLinkCache,getVnfFromLinkCache
|
||||
|
||||
import random
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
|
||||
@ -341,7 +342,14 @@ def link_to_vnf_from_tweet_data(tweet,video_link):
|
||||
|
||||
def link_to_vnf_from_unofficial_api(video_link):
|
||||
print(" ➤ [ + ] Attempting to download tweet info from UNOFFICIAL Twitter API")
|
||||
tweet = twExtract.extractStatus(video_link)
|
||||
try:
|
||||
tweet = twExtract.extractStatus(video_link)
|
||||
except Exception as e:
|
||||
print('print(" ➤ [ !!! ] Local UNOFFICIAL API Failed")')
|
||||
if ('apiMirrors' in config['config'] and len(config['config']['apiMirrors']) > 0):
|
||||
mirror = random.choice(config['config']['apiMirrors'])
|
||||
print(" ➤ [ + ] Using API Mirror: "+mirror)
|
||||
tweet = requests.get(mirror+"?url="+video_link).json()
|
||||
print (" ➤ [ ✔ ] Unofficial API Success")
|
||||
return link_to_vnf_from_tweet_data(tweet,video_link)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user