Handle empty input folders
This commit is contained in:
parent
6deefc7ea8
commit
d5f6b4bfd7
1 changed files with 11 additions and 8 deletions
19
slider.py
19
slider.py
|
@ -26,15 +26,18 @@ def random():
|
|||
|
||||
@app.route("/random_image/")
|
||||
def random_image():
|
||||
last_modified_time, last_modified_file = max(
|
||||
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
||||
)
|
||||
try:
|
||||
last_modified_time, last_modified_file = max(
|
||||
(f.stat().st_mtime, f) for f in imgdir.glob(img_glob)
|
||||
)
|
||||
|
||||
if time() - last_modified_time <= 60:
|
||||
selected_image = last_modified_file.relative_to(imgdir)
|
||||
else:
|
||||
images = list(imgdir.glob(img_glob))
|
||||
selected_image = choice(images).relative_to(imgdir)
|
||||
if time() - last_modified_time <= 60:
|
||||
selected_image = last_modified_file.relative_to(imgdir)
|
||||
else:
|
||||
images = list(imgdir.glob(img_glob))
|
||||
selected_image = choice(images).relative_to(imgdir)
|
||||
except ValueError:
|
||||
return redirect(url_for("static", filename="clear.gif"))
|
||||
|
||||
return redirect(
|
||||
url_for("image", filename=selected_image)
|
||||
|
|
Loading…
Reference in a new issue