You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
935 B
Python
34 lines
935 B
Python
1 year ago
|
from flask import Flask, render_template, make_response, send_file
|
||
|
import os
|
||
|
import random
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
req_count = 0
|
||
|
|
||
|
static_dir = os.path.join(os.path.dirname(__file__), 'static/')
|
||
|
|
||
|
@app.route('/static/<path:path>')
|
||
|
def static_file(path):
|
||
|
return send_file(os.path.join(static_dir, path))
|
||
|
|
||
|
@app.route("/")
|
||
|
def index():
|
||
|
global req_count
|
||
|
cat_files = os.listdir(os.path.join(static_dir, 'img/'))
|
||
|
file = random.choice(cat_files)
|
||
|
is_stoner = os.path.basename(file) == 'stoner_cat.gif'
|
||
|
url = '/static/img/' + file
|
||
|
req_count += 1
|
||
|
return render_template("index.html", url=url, is_stoner=is_stoner)
|
||
|
|
||
|
@app.route("/request_count")
|
||
|
def request_count():
|
||
|
response = make_response(str(req_count), 200)
|
||
|
response.mimetype = "text/plain"
|
||
|
return response
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
app.config['TEMPLATES_AUTO_RELOAD'] = True
|
||
|
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
|