This commit is contained in:
2026-02-25 09:00:23 +00:00
parent 96960c17a1
commit 942a3adaf6

View File

@@ -2,12 +2,11 @@ import urllib.request
import json
import socket
from datetime import datetime
import subprocess
machine_name = socket.gethostname()
url = "http://192.168.50.27:5000/lookup"
payload = {
"name": machine_name,
}
DEFAULT_SHUTDOWN = "21:00"
LAST_VALUE = 0
def get_data():
data = json.dumps(payload).encode("utf-8")
@@ -28,15 +27,27 @@ def get_data():
except:
return None
data = get_data()
if data is None or data["noshutdown"] == 1:
exit
def to_seconds(t):
return t.hour * 3600 + t.minute * 60 + t.second
time = to_seconds(datetime.strptime(data["time"], "%H:%M").time())
machine_name = socket.gethostname()
url = "http://192.168.50.27:5000/lookup"
payload = {
"name": machine_name,
}
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())
print(time)
print(now)
print(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)