Added config system, Updated readme, Fixed DB connections stalling with multiple uWSGI workers, Made it less prone to crashing if necessary files are not present

This commit is contained in:
robinuniverse 2021-07-11 15:48:17 -05:00
parent 4aa3c9a59e
commit 2f9f160b34
4 changed files with 19 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
config.json

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 3.5 MiB

View File

@ -10,7 +10,7 @@ just put the url to the server, and directly after, the full URL to the tweet yo
**I now have a copy of this running on a Linode server, you can use it via the following url**
https://fxtwitter.com/`<twitter video url>`
https://fxtwitter.com/`twitter video url` or `last half of twitter url (everything past twitter.com/)`
You can also simply type out 'fx' directly before 'twitter.com' in any valid twitter video url, and that will convert it into a working TwitFix url, for example:

View File

@ -3,19 +3,34 @@ import pymongo
import youtube_dl
import json
import re
import os
app = Flask(__name__)
pathregex = re.compile("\\w{1,15}\\/status\\/\\d{19}")
link_cache_system = "json" # Select your prefered link cache system, "db" for mongoDB or "json" for locally writing a json file ( not great if using multiple workers )
if not os.path.exists("config.json"):
with open("config.json", "w") as outfile:
default = {"config":{"link_cache":"json","database":"[url to mongo database goes here]","method":"youtube-dl"},"api":{"consumer_key":"[consumer key goes here]","consumer_secret":"[consumer secret goes here]","access_token_key":"[access token key goes here]","access_token_secret":"[access token secret goes here]"}}
json.dump(default, outfile, indent=4, sort_keys=True)
f = open("config.json")
config = json.load(f)
f.close()
link_cache_system = config['config']['link_cache'] # Select your prefered link cache system, "db" for mongoDB or "json" for locally writing a json file ( not great if using multiple workers )
if link_cache_system == "json":
link_cache = {}
if not os.path.exists("config.json"):
with open("config.json", "w") as outfile:
deflinkcache = {"test":"test"}
json.dump(deflinkcache, outfile, indent=4, sort_keys=True)
f = open('links.json',)
link_cache = json.load(f)
f.close()
elif link_cache_system == "db":
client = pymongo.MongoClient("PUT YOUR MONGODB URL HERE")
client = pymongo.MongoClient(config['config']['database'], connect=False)
db = client.TwitFix
@app.route('/')