36 lines
776 B
Python
36 lines
776 B
Python
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,
|
|
}
|
|
|
|
def get_data():
|
|
data = json.dumps(payload).encode("utf-8")
|
|
|
|
req = urllib.request.Request(
|
|
url,
|
|
headers={"Content-Type": "application/json"},
|
|
data=data,
|
|
method="POST"
|
|
)
|
|
|
|
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
|
|
|
|
data = get_data()
|
|
if data is None or data["noshutdown"] == 1:
|
|
exit
|
|
|
|
time = datetime.strptime(data["time"], "%H:%M").time()
|
|
print(time) |