Wallpaper-Changer/wrapper.py

41 lines
1.3 KiB
Python
Raw Normal View History

2020-12-03 01:44:45 +00:00
from os import mkdir, getcwd
from os.path import isfile, isdir
from subprocess import Popen, call
from time import sleep
CONFIG = ".config"
HISTORY = ".history"
def integrity_check():
for i in [1]:
if not isfile(CONFIG):
pass
elif len(open(CONFIG, "r").read().split()) < 4:
pass
else:
break
open(CONFIG, "w").write("600\n1\n0\n1")
print(CONFIG + " is missing")
print("generating " + CONFIG + " with default value of\n Interval = 600 seconds\n Save Wallpapers = True\n Start Hidden = False\n Approximate Time = True")
if not isfile(HISTORY):
open(HISTORY, "w").write("")
print(HISTORY + " is missing")
print("generating " + HISTORY)
if not isdir(".\\Images"):
mkdir(".\\Images")
print(getcwd() + "\\Images is missing")
print("generating " + getcwd() + ".\\Images")
while True:
try:
integrity_check()
if int(open(CONFIG, "r").read().split()[3]):
2020-12-03 01:47:16 +00:00
call(["backend.py"], shell=True)
2020-12-03 01:44:45 +00:00
else:
2020-12-03 01:47:16 +00:00
Popen(["backend.py"], shell=True)
2020-12-03 01:44:45 +00:00
sleep(float(open(CONFIG, "r").read().split()[0]))
except Exception as E:
print("Error: " + type(E).__name__)
if type(E).__name__ == "KeyboardInterrupt":
break