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