From 4104ee47c4cd48efe7b71dcaefe59e91af80dbe9 Mon Sep 17 00:00:00 2001 From: Namonay Date: Wed, 25 Feb 2026 10:40:55 +0000 Subject: [PATCH] a --- client/bs_shutdown.py | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/client/bs_shutdown.py b/client/bs_shutdown.py index 839ea85..2234e23 100644 --- a/client/bs_shutdown.py +++ b/client/bs_shutdown.py @@ -8,6 +8,12 @@ DEFAULT_SHUTDOWN = "21:00" LAST_VALUE = 0 +machine_name = socket.gethostname() +url = "http://192.168.50.27:5000/lookup" +payload = { + "name": machine_name, +} + def get_data(): data = json.dumps(payload).encode("utf-8") @@ -30,24 +36,25 @@ def get_data(): def to_seconds(t): return t.hour * 3600 + t.minute * 60 + t.second -machine_name = socket.gethostname() -url = "http://192.168.50.27:5000/lookup" -payload = { - "name": machine_name, -} +def update(): + data = get_data() + if data["noshutdown"] == 1: + exit + if data is None: + time = to_seconds(datetime.strptime(DEFAULT_SHUTDOWN, "%H:%M").time()) + else: + time = to_seconds(datetime.strptime(data["time"], "%H:%M").time()) + now = to_seconds(datetime.now().time()) + if (time - now) < 0: + exit + if (time != LAST_VALUE and LAST_VALUE != 0): + LAST_VALUE = time + subprocess.run(["shutdown", "/a"]) + print("new val detected") + print("shutting down in " + (time - now) + " seconds") + # subprocess.run(["shutdown", "/s", "/t", (time - now), " "]) + print(time - now) -data = get_data() -if data["noshutdown"] == 1: - exit -if data is None: - time = to_seconds(datetime.strptime(DEFAULT_SHUTDOWN, "%H:%M").time()) -else: - time = to_seconds(datetime.strptime(data["time"], "%H:%M").time()) -now = to_seconds(datetime.now().time()) -if (time - now) < 0: - exit -if (time != LAST_VALUE): - LAST_VALUE = time - subprocess.run(["shutdown", "/a"]) -# subprocess.run(["shutdown", "/s", "/t", (time - now), " "]) -print(time - now) +if __name__ == '__main__': + update() + time.sleep(30) \ No newline at end of file