WallPyPer/func.py

45 lines
1.1 KiB
Python
Raw Normal View History

2022-07-02 15:34:01 +00:00
import json
2022-06-18 18:49:00 +00:00
import os
import random
2022-07-01 17:30:35 +00:00
import sys
2022-06-18 18:49:00 +00:00
def run(command,output=False):
devNull = ">/dev/null"
if output == True:
os.system(command)
else:
os.system(command + devNull)
def kill():
2022-06-29 13:47:58 +00:00
'''
back4.sh will output artifacts if run more 2 processes
It function read PID in /tmp/back4.sh.pid, and kill process.
'''
with open('/tmp/back4.sh.pid','r') as file:
2022-06-18 18:49:00 +00:00
for pid in file:
run(f'kill {pid}')
2022-07-02 15:34:01 +00:00
def configParsing():
pathToConfig = os.path.expanduser('~')+'/.config/wallpyper/config'
with open(pathToConfig) as file:
contentFile = file.read()
config = json.loads(contentFile)
return config
2022-06-29 13:47:58 +00:00
def setWallPaper():
2022-07-02 15:34:01 +00:00
config = configParsing()
PATH = config['path_to_wallpapers']
files = os.listdir(PATH)
media = random.choices(files)[0]
2022-06-18 18:49:00 +00:00
if media[-4:] != '.gif':
run(f"feh --bg-scale {PATH}{media}")
else:
2022-06-29 13:47:58 +00:00
run(f"back4.sh auto {PATH}{media} & echo $! > /tmp/back4.sh.pid",True)
# > tmp/back4.sh.pid write PID for kill()
2022-07-02 15:34:01 +00:00
setWallPaper()