summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-20 15:02:01 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-20 15:02:01 +1000
commit13444e46bb31583c2834d4d011a104361d22e29e (patch)
tree2098b00e8a45773d1126173c4df781a48009e9b2
parentd4c181fa477f6270067e313dff7e1dc339cda800 (diff)
Image: Random image, select image file.
-rwxr-xr-xwal13
1 files changed, 11 insertions, 2 deletions
diff --git a/wal b/wal
index df99d7f..a7441a2 100755
--- a/wal
+++ b/wal
@@ -115,14 +115,23 @@ def get_image(img):
if image.is_file():
wal_img = image
+ # Pick a random image from the directory.
elif image.is_dir():
- rand = random.choice(os.listdir(image))
- rand_img = "%s/%s" % (str(image), rand)
+ images = []
+ file_types = ('*.png', '*.jpg', '*.jpeg', '*.jpe', '*.gif')
+ for files in file_types:
+ images.extend(glob.glob(str(image) + "/" + files))
+
+ rand_img = random.choice(images)
rand_img = pathlib.Path(rand_img)
if rand_img.is_file():
wal_img = rand_img
+ else:
+ print("error: No valid image file found.")
+ exit(1)
+
print("image: Using image", wal_img)
return wal_img