-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
88 lines (73 loc) · 2.23 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from flask import Flask, send_file, jsonify, render_template, request, redirect
from flask_limiter import Limiter
from flask_caching import Cache
import utilset as uls
from flask_cors import CORS
from flask_minify import Minify, decorators as minify_decorators
from flask_limiter.util import get_remote_address
from flask_compress import Compress
from flask_talisman import Talisman
import get_database as qdb
import routing as rt
import asyncio
import threading
import background_seeder as seeder
import random
from waitress import serve
app = Flask(__name__)
# Minify(app, go=False, passive=True)
CORS(app)
# Compress(app)
# Talisman(app)
cache = Cache(app=app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': 'tmp/flaskcache'})
limiter = Limiter(
get_remote_address,
app=app,
default_limits=["7 per second"],
storage_uri="memory://",
strategy="moving-window",
)
@cache.memoize(timeout=uls.get_seconds(minutes=5))
def list_cached_quotes():
return qdb.fetch_multiple_quotes(count=1000)
rt.domain_based_routing(app)
@app.route('/random-quote-image')
def random_quote_image():
return send_file(f"all_quote_images/{random.choice(list_cached_quotes()).uid}.webp")
@app.route('/vote-a-quote')
@app.route('/vote')
def vote_a_quote():
return render_template('vote-a-quote.html')
@app.route('/show-the-quotes')
def show_the_quotes():
return render_template('show-the-quotes.html')
<<<<<<< Updated upstream:app.py
@app.route('/robots.txt')
def robots():
return send_file('static/robots.txt')
@app.route('/ads.txt')
def ads_txt():
return render_template('static/ads.txt')
=======
>>>>>>> Stashed changes:main.py
@app.route('/sitemap')
@app.route('/sitemap.xml')
def sitemap():
return send_file('static/sitemap.xml')
@app.route('/legal')
def legal():
return redirect('https://github.com/skaffa/random-quote')
@app.route('/robots.txt')
def robots():
return send_file('static/robots.txt')
@app.route('/')
@app.errorhandler(404)
def home(e=None):
print("Index it is")
return redirect("/show-the-quotes", code=302)
def run_seeder():
asyncio.run(seeder.seeder())
if __name__ == '__main__':
seeder_thread = threading.Thread(target=run_seeder)
seeder_thread.start()
serve(app, host='0.0.0.0', port=443)