2018-10-28 21:49:15 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2018-11-03 13:00:06 +00:00
|
|
|
from flask import Flask, render_template, send_from_directory, redirect, url_for
|
2018-10-29 18:52:51 +00:00
|
|
|
from random import randint
|
2018-11-06 19:13:35 +00:00
|
|
|
from os import listdir, makedirs
|
2018-11-05 20:57:26 +00:00
|
|
|
from random import choice
|
2018-11-06 19:13:35 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from PIL import Image
|
2018-10-28 21:49:15 +00:00
|
|
|
|
2018-11-03 12:21:26 +00:00
|
|
|
import config
|
|
|
|
|
2018-10-28 21:49:15 +00:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
2018-10-29 19:35:45 +00:00
|
|
|
|
2018-10-28 21:49:15 +00:00
|
|
|
@app.route("/")
|
2018-11-05 20:57:26 +00:00
|
|
|
def random():
|
2018-11-05 21:01:57 +00:00
|
|
|
return render_template("random.html", refresh=config.refresh)
|
2018-10-29 19:35:45 +00:00
|
|
|
|
2018-10-28 21:49:15 +00:00
|
|
|
|
2018-11-05 20:57:26 +00:00
|
|
|
@app.route("/random_image/")
|
2018-11-03 13:00:06 +00:00
|
|
|
def random_image():
|
2018-11-05 20:57:26 +00:00
|
|
|
filename = choice(listdir(config.imgdir))
|
2018-11-03 13:00:06 +00:00
|
|
|
return redirect(url_for("image", filename=filename))
|
|
|
|
|
|
|
|
|
2018-11-03 12:21:26 +00:00
|
|
|
@app.route("/img/<path:filename>")
|
|
|
|
def image(filename):
|
2018-11-06 19:13:35 +00:00
|
|
|
scaled_img_dir = Path(config.imgdir) / ".slider" / "fhd"
|
|
|
|
if not scaled_img_dir.exists():
|
|
|
|
makedirs(scaled_img_dir)
|
|
|
|
if not (scaled_img_dir / filename).exists():
|
|
|
|
img = Image.open(Path(config.imgdir) / filename)
|
|
|
|
img.thumbnail((1920, 1080))
|
|
|
|
img.save(scaled_img_dir / filename)
|
|
|
|
|
|
|
|
return send_from_directory(scaled_img_dir, filename)
|
2018-11-03 12:21:26 +00:00
|
|
|
|
|
|
|
|
2018-10-28 21:49:15 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
app.run()
|