From 76f857ca0a052286ddb57f889e633a3269224465 Mon Sep 17 00:00:00 2001 From: Namonay Date: Tue, 24 Feb 2026 14:23:56 +0000 Subject: [PATCH] add: time --- client/bs_shutdown.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/client/bs_shutdown.py b/client/bs_shutdown.py index a1870a6..765df01 100644 --- a/client/bs_shutdown.py +++ b/client/bs_shutdown.py @@ -1,25 +1,36 @@ import urllib.request import json import socket +import datetime machine_name = socket.gethostname() url = "http://192.168.50.27:5000/lookup" - payload = { "name": machine_name, } -data = json.dumps(payload).encode("utf-8") +def get_data(): + data = json.dumps(payload).encode("utf-8") -req = urllib.request.Request( - url, - headers={"Content-Type": "application/json"}, - data=data, - method="POST" -) + req = urllib.request.Request( + url, + headers={"Content-Type": "application/json"}, + data=data, + method="POST" + ) -with urllib.request.urlopen(req, timeout=10) as response: - data = response.read() - json_data = json.loads(data) + try: + with urllib.request.urlopen(req, timeout=10) as response: + data = response.read() + json_data = json.loads(data) + print(json_data) + return json_data + except: + return None -print(json_data) \ No newline at end of file +data = get_data() +if data is None or data["noshutdown"] == 1: + return + +time = datetime.strptime(data["time"], "%H:%M").time() +print(time) \ No newline at end of file