Removed dependency on official Twitter API
This commit is contained in:
parent
9d2c56ba95
commit
d453933d95
@ -7,18 +7,12 @@ if ('RUNNING_SERVERLESS' in os.environ and os.environ['RUNNING_SERVERLESS'] == '
|
|||||||
"link_cache":os.environ["VXTWITTER_LINK_CACHE"],
|
"link_cache":os.environ["VXTWITTER_LINK_CACHE"],
|
||||||
"database":os.environ["VXTWITTER_DATABASE"],
|
"database":os.environ["VXTWITTER_DATABASE"],
|
||||||
"table":os.environ["VXTWITTER_CACHE_TABLE"],
|
"table":os.environ["VXTWITTER_CACHE_TABLE"],
|
||||||
"method":os.environ["VXTWITTER_METHOD"],
|
|
||||||
"color":os.environ["VXTWITTER_COLOR"],
|
"color":os.environ["VXTWITTER_COLOR"],
|
||||||
"appname": os.environ["VXTWITTER_APP_NAME"],
|
"appname": os.environ["VXTWITTER_APP_NAME"],
|
||||||
"repo": os.environ["VXTWITTER_REPO"],
|
"repo": os.environ["VXTWITTER_REPO"],
|
||||||
"url": os.environ["VXTWITTER_URL"],
|
"url": os.environ["VXTWITTER_URL"],
|
||||||
"combination_method": os.environ["VXTWITTER_COMBINATION_METHOD"] # can either be 'local' or a URL to a server handling requests in the same format
|
"combination_method": os.environ["VXTWITTER_COMBINATION_METHOD"], # can either be 'local' or a URL to a server handling requests in the same format
|
||||||
},
|
"apiMirrors":[]
|
||||||
"api":{"api_key":os.environ["VXTWITTER_TWITTER_API_KEY"],
|
|
||||||
"api_secret":os.environ["VXTWITTER_TWITTER_API_SECRET"],
|
|
||||||
"access_token":os.environ["VXTWITTER_TWITTER_ACCESS_TOKEN"],
|
|
||||||
"access_secret":os.environ["VXTWITTER_TWITTER_ACCESS_SECRET"],
|
|
||||||
"apiMirrors":[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
@ -30,18 +24,12 @@ else:
|
|||||||
"link_cache":"json",
|
"link_cache":"json",
|
||||||
"database":"[url to mongo database goes here]",
|
"database":"[url to mongo database goes here]",
|
||||||
"table":"TwiFix",
|
"table":"TwiFix",
|
||||||
"method":"youtube-dl",
|
|
||||||
"color":"#43B581",
|
"color":"#43B581",
|
||||||
"appname": "vxTwitter",
|
"appname": "vxTwitter",
|
||||||
"repo": "https://github.com/dylanpdx/BetterTwitFix",
|
"repo": "https://github.com/dylanpdx/BetterTwitFix",
|
||||||
"url": "https://vxtwitter.com",
|
"url": "https://vxtwitter.com",
|
||||||
"combination_method": "local" # can either be 'local' or a URL to a server handling requests in the same format
|
"combination_method": "local", # can either be 'local' or a URL to a server handling requests in the same format
|
||||||
},
|
"apiMirrors":[]
|
||||||
"api":{"api_key":"[api_key goes here]",
|
|
||||||
"api_secret":"[api_secret goes here]",
|
|
||||||
"access_token":"[access_token goes here]",
|
|
||||||
"access_secret":"[access_secret goes here]",
|
|
||||||
"apiMirrors":[]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ python-dateutil==2.8.2
|
|||||||
requests==2.27.1
|
requests==2.27.1
|
||||||
s3transfer==0.5.2
|
s3transfer==0.5.2
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
twitter==1.19.3
|
|
||||||
typing-extensions==4.1.1
|
typing-extensions==4.1.1
|
||||||
urllib3==1.26.9
|
urllib3==1.26.9
|
||||||
Werkzeug==2.0.3
|
Werkzeug==2.0.3
|
||||||
|
30
twitfix.py
30
twitfix.py
@ -2,9 +2,7 @@ from random import Random, random
|
|||||||
from weakref import finalize
|
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 import Flask, render_template, request, redirect, abort, Response, send_from_directory, url_for, send_file, make_response, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
import yt_dlp
|
|
||||||
import textwrap
|
import textwrap
|
||||||
import twitter
|
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -37,12 +35,6 @@ generate_embed_user_agents = [
|
|||||||
"Mozilla/5.0 (compatible; January/1.0; +https://gitlab.insrt.uk/revolt/january)",
|
"Mozilla/5.0 (compatible; January/1.0; +https://gitlab.insrt.uk/revolt/january)",
|
||||||
"test"]
|
"test"]
|
||||||
|
|
||||||
|
|
||||||
# If method is set to API or Hybrid, attempt to auth with the Twitter API
|
|
||||||
if config['config']['method'] in ('api', 'hybrid'):
|
|
||||||
auth = twitter.oauth.OAuth(config['api']['access_token'], config['api']['access_secret'], config['api']['api_key'], config['api']['api_secret'])
|
|
||||||
twitter_api = twitter.Twitter(auth=auth)
|
|
||||||
|
|
||||||
@app.route('/') # If the useragent is discord, return the embed, if not, redirect to configured repo directly
|
@app.route('/') # If the useragent is discord, return the embed, if not, redirect to configured repo directly
|
||||||
def default():
|
def default():
|
||||||
user_agent = request.headers.get('user-agent')
|
user_agent = request.headers.get('user-agent')
|
||||||
@ -354,23 +346,11 @@ def link_to_vnf_from_api(video_link):
|
|||||||
return link_to_vnf_from_tweet_data(tweet,video_link)
|
return link_to_vnf_from_tweet_data(tweet,video_link)
|
||||||
|
|
||||||
def link_to_vnf(video_link): # Return a VideoInfo object or die trying
|
def link_to_vnf(video_link): # Return a VideoInfo object or die trying
|
||||||
if config['config']['method'] == 'hybrid':
|
try:
|
||||||
try:
|
return link_to_vnf_from_unofficial_api(video_link)
|
||||||
return link_to_vnf_from_unofficial_api(video_link)
|
except Exception as e:
|
||||||
except Exception as e:
|
print(" ➤ [ !!! ] Unofficial Twitter API Failed")
|
||||||
print(" ➤ [ !!! ] UNOFFICIAL API Failed")
|
print(e)
|
||||||
print(e)
|
|
||||||
|
|
||||||
elif config['config']['method'] == 'api':
|
|
||||||
try:
|
|
||||||
return link_to_vnf_from_api(video_link)
|
|
||||||
except Exception as e:
|
|
||||||
print(" ➤ [ X ] API Failed")
|
|
||||||
print(e)
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
print("Please set the method key in your config file to 'api' or 'hybrid'")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def message(text):
|
def message(text):
|
||||||
return render_template(
|
return render_template(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user