diff --git a/config.py b/config.py index ce3bda5..3098ac2 100644 --- a/config.py +++ b/config.py @@ -1,4 +1,5 @@ imgdir = "." +recursive = True refresh = 5 cachedir = "/tmp/webslider" resolution = (1920, 1080) diff --git a/requirements.txt b/requirements.txt index 533b660..2d2ba95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Flask==1.0.2 Pillow==5.3.0 Click==7.0 +waitress==1.1.0 diff --git a/server.py b/server.py new file mode 100755 index 0000000..d5e1cd4 --- /dev/null +++ b/server.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 + +from waitress import serve + +import slider + +serve(slider.app, host="0.0.0.0", port=8080) + diff --git a/slider.py b/slider.py index 382e270..556b926 100755 --- a/slider.py +++ b/slider.py @@ -14,6 +14,7 @@ import config app = Flask(__name__) imgdir = Path(config.imgdir).expanduser().resolve() +img_glob = "**/*.jpg" if config.recursive else "*.jpg" cache_resolution = config.resolution cache_dir = Path(config.cachedir) / ("%sx%s" % cache_resolution) @@ -25,7 +26,6 @@ def random(): @app.route("/random_image/") def random_image(): - img_glob = "*jpg" last_modified_time, last_modified_file = max( (f.stat().st_mtime, f) for f in imgdir.glob(img_glob) ) @@ -36,7 +36,10 @@ def random_image(): images = list(imgdir.glob(img_glob)) selected_image = choice(images).relative_to(imgdir) - return redirect(url_for("image", filename=selected_image) + "?hash=%s" % get_cache_filename(selected_image)) + return redirect( + url_for("image", filename=selected_image) + + "?hash=%s" % get_cache_filename(selected_image) + ) @app.route("/img/") @@ -77,7 +80,7 @@ def get_cache_filename(filename): def pre_cache_images(): - for image_file in sorted(imgdir.glob("*.jpg")): + for image_file in sorted(imgdir.glob(img_glob)): create_cache_file(image_file.relative_to(imgdir))