From efc5fc1501c44bfe636e9d86f151d4fc3b445f1d Mon Sep 17 00:00:00 2001 From: Arthur Date: Sat, 2 Jul 2022 20:34:01 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config | 1 + func.py | 24 ++++++++++++++++-------- main.py | 4 ++-- 3 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 config diff --git a/config b/config new file mode 100644 index 0000000..2eda8e2 --- /dev/null +++ b/config @@ -0,0 +1 @@ +path_to_wallpapers = "/home/arthur/img/Wallpapers/wallpyper" diff --git a/func.py b/func.py index 908eb29..3d137be 100644 --- a/func.py +++ b/func.py @@ -1,14 +1,7 @@ +import json import os import random import sys -home = os.path.expanduser('~') -sys.path.insert(0, home+"/.config") -#sys.path.insert(0, '.config/wallpyper') -from wallpyper import config - - -PATH = config.path_to_wallpapers -files = os.listdir(PATH) def run(command,output=False): devNull = ">/dev/null" @@ -26,7 +19,20 @@ def kill(): for pid in file: run(f'kill {pid}') +def configParsing(): + pathToConfig = os.path.expanduser('~')+'/.config/wallpyper/config' + + with open(pathToConfig) as file: + contentFile = file.read() + config = json.loads(contentFile) + return config + def setWallPaper(): + config = configParsing() + + PATH = config['path_to_wallpapers'] + files = os.listdir(PATH) + media = random.choices(files)[0] if media[-4:] != '.gif': @@ -34,3 +40,5 @@ def setWallPaper(): else: run(f"back4.sh auto {PATH}{media} & echo $! > /tmp/back4.sh.pid",True) # > tmp/back4.sh.pid write PID for kill() + +setWallPaper() diff --git a/main.py b/main.py index 0446342..7e74025 100755 --- a/main.py +++ b/main.py @@ -15,5 +15,5 @@ if __name__ == '__main__': start() sched = BlockingScheduler() - sched.add_job(start,'interval',minutes=1) - sched.start() + sched.add_job(start,'interval',minutes=configParsing()['value']) + sched.start()