From bee10ecb8685c80a67816e8a259ed8449084c4c5 Mon Sep 17 00:00:00 2001 From: CramMK Date: Tue, 9 Jun 2020 14:37:47 +0200 Subject: [PATCH] Update Wallpaperscript --- .gitmodules | 3 -- dotfiles/scripts/randomwallpaper | 1 - dotfiles/scripts/wallpaper.py | 70 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) delete mode 160000 dotfiles/scripts/randomwallpaper create mode 100755 dotfiles/scripts/wallpaper.py diff --git a/.gitmodules b/.gitmodules index 86a1231..4f4e193 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "dotfiles/zsh/ohmyzsh"] path = dotfiles/zsh/ohmyzsh url = https://github.com/ohmyzsh/ohmyzsh -[submodule "dotfiles/scripts/randomwallpaper"] - path = dotfiles/scripts/randomwallpaper - url = https://github.com/CramMK/randomwallpaper diff --git a/dotfiles/scripts/randomwallpaper b/dotfiles/scripts/randomwallpaper deleted file mode 160000 index 0a973ca..0000000 --- a/dotfiles/scripts/randomwallpaper +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0a973cafe8b64ee24f59813569c313ba96ee3ae1 diff --git a/dotfiles/scripts/wallpaper.py b/dotfiles/scripts/wallpaper.py new file mode 100755 index 0000000..c63c7e6 --- /dev/null +++ b/dotfiles/scripts/wallpaper.py @@ -0,0 +1,70 @@ +#!/usr/bin/python3 + +import os +import sys +import random +import re +import argparse + + +def get_wallpapers(query: str, path: str): + "Fetch a wallpaper" + + # Search through all wallpapers + wallpapers = [f for f in os.listdir(path) if re.search(r"png|jpg", f)] + queried_wallpapers = [f for f in wallpapers if re.search(rf"{query}", f)] + + return queried_wallpapers + +def pick_wallpaper(wallpaper_list, *args): + # Error handling + if not wallpaper_list: + print("No wallpapers found!") + sys.exit(1) + else: + new_wallpaper = random.choice(wallpaper_list) + + return new_wallpaper + +def list_wallpapers(wallpaper_list, *args): + print("Wallpapers matching your query:") + for wallpaper in wallpaper_list: + print(wallpaper) + + +if __name__ == "__main__": + + ### DEFAULT WALLPAPER DIRECTORY HERE + path = "~/wallpaper" + + parser = argparse.ArgumentParser() + parser.add_argument("-q", "--query", help="Refine selection") + parser.add_argument("-p", "--path", help="Path to wallpaper directory") + parser.add_argument("-l", "--list", action="store_true", help="List potential wallpapers" ) + args = parser.parse_args() + + query = "" + if args.query: + query = args.query + print(f"Searching for wallpapers filename matching: {query}") + + if args.path: + path = args.path + print(f"Searching in: {path}") + + # Get a list of all wallpapers + wallpaper_list = get_wallpapers(query, path) + + if args.list: + print("=================================================") + print("Arg '--list' is set. No wallpaper will be applied") + print("=================================================") + list_wallpapers(wallpaper_list) + sys.exit(1) + + # Pick one wallpaper + query_result = pick_wallpaper(wallpaper_list) + wallpaper = path + "/" + query_result + + os.system(f"feh --bg-scale {wallpaper}") + print(f"Updated wallpaper to: {wallpaper}")