This commit is contained in:
2026-02-25 13:32:06 +00:00
parent 2ca97cba47
commit d63d9cdb78

View File

@@ -37,13 +37,31 @@ def get_data():
def to_seconds(t):
return t.hour * 3600 + t.minute * 60 + t.second
def set_shutdown(time, now):
global LAST_VALUE
if (time - now) < 0 or time == LAST_VALUE:
return
LAST_VALUE = time
print("[BS Shutdown] shutting down in " + str(time - now) + " seconds")
# subprocess.run(["shutdown", "/s", "/t", (time - now), " "])
def remove_shutdown():
print("[BS Shutdown] Removed shutdown")
# subprocess.run(["shutdown", "/s", "/t", (time - now), " "])
def update():
global LAST_VALUE
data = get_data()
if data is not None and data["noshutdown"] == 1:
if (LAST_VALUE != 0):
subprocess.run(["shutdown", "/a"])
LAST_VALUE = 0
remove_shutdown()
return
if data is None:
time = to_seconds(datetime.strptime(DEFAULT_SHUTDOWN, "%H:%M").time())
else:
@@ -54,17 +72,13 @@ def update():
return
if (time == LAST_VALUE):
print("Nothing changed")
return
if (time != LAST_VALUE):
if (LAST_VALUE != 0):
subprocess.run(["shutdown", "/a"])
print("new val detected")
LAST_VALUE = time
print("shutting down in " + str(time - now) + " seconds")
# subprocess.run(["shutdown", "/s", "/t", (time - now), " "])
print(time - now)
if (LAST_VALUE != 0):
remove_shutdown()
print("[BS Shutdown] New value")
LAST_VALUE = time
set_shutdown(time, now)
if __name__ == '__main__':
while True: