Files

37 lines
846 B
Python

from flask import Flask, render_template, send_from_directory, abort
import json
import random
app_base = Flask(__name__)
def get_random_image():
try:
with open("images/images.json") as f:
images = json.load(f)
return random.choice(images["images"])
except Exception as e:
return {
"filename": "https://picsum.photos/200/300",
"author": f"{e}",
"source": "picsum.photos"
}
@app_base.route("/")
def index():
return render_template(
"index.html",
image=get_random_image()
)
@app_base.route("/images/<filename>")
def host_image(filename):
try:
return send_from_directory("images",filename)
except Exception:
abort(404)
if __name__ == "__main__":
app_base.run(host="0.0.0.0", port=5000)