From d453933d95d4212874b83e186b0bf127d26f39a8 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 15 Sep 2022 20:11:00 +0100 Subject: [PATCH] Removed dependency on official Twitter API --- configHandler.py | 20 ++++---------------- requirements.txt | 1 - twitfix.py | 30 +++++------------------------- 3 files changed, 9 insertions(+), 42 deletions(-) diff --git a/configHandler.py b/configHandler.py index f507a13..d19ea63 100644 --- a/configHandler.py +++ b/configHandler.py @@ -7,18 +7,12 @@ if ('RUNNING_SERVERLESS' in os.environ and os.environ['RUNNING_SERVERLESS'] == ' "link_cache":os.environ["VXTWITTER_LINK_CACHE"], "database":os.environ["VXTWITTER_DATABASE"], "table":os.environ["VXTWITTER_CACHE_TABLE"], - "method":os.environ["VXTWITTER_METHOD"], "color":os.environ["VXTWITTER_COLOR"], "appname": os.environ["VXTWITTER_APP_NAME"], "repo": os.environ["VXTWITTER_REPO"], "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 - }, - "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":[] + "combination_method": os.environ["VXTWITTER_COMBINATION_METHOD"], # can either be 'local' or a URL to a server handling requests in the same format + "apiMirrors":[] } } else: @@ -30,18 +24,12 @@ else: "link_cache":"json", "database":"[url to mongo database goes here]", "table":"TwiFix", - "method":"youtube-dl", "color":"#43B581", "appname": "vxTwitter", "repo": "https://github.com/dylanpdx/BetterTwitFix", "url": "https://vxtwitter.com", - "combination_method": "local" # can either be 'local' or a URL to a server handling requests in the same format - }, - "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":[] + "combination_method": "local", # can either be 'local' or a URL to a server handling requests in the same format + "apiMirrors":[] } } diff --git a/requirements.txt b/requirements.txt index 95ff18c..30d3fa0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,7 +18,6 @@ python-dateutil==2.8.2 requests==2.27.1 s3transfer==0.5.2 six==1.16.0 -twitter==1.19.3 typing-extensions==4.1.1 urllib3==1.26.9 Werkzeug==2.0.3 diff --git a/twitfix.py b/twitfix.py index cc3f37b..a11a2c7 100644 --- a/twitfix.py +++ b/twitfix.py @@ -2,9 +2,7 @@ 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 -import yt_dlp import textwrap -import twitter import requests import re import os @@ -37,12 +35,6 @@ generate_embed_user_agents = [ "Mozilla/5.0 (compatible; January/1.0; +https://gitlab.insrt.uk/revolt/january)", "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 def default(): 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) def link_to_vnf(video_link): # Return a VideoInfo object or die trying - if config['config']['method'] == 'hybrid': - try: - return link_to_vnf_from_unofficial_api(video_link) - except Exception as e: - print(" ➤ [ !!! ] UNOFFICIAL API Failed") - 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 + try: + return link_to_vnf_from_unofficial_api(video_link) + except Exception as e: + print(" ➤ [ !!! ] Unofficial Twitter API Failed") + print(e) def message(text): return render_template(