add: time
This commit is contained in:
@@ -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)
|
||||
data = get_data()
|
||||
if data is None or data["noshutdown"] == 1:
|
||||
return
|
||||
|
||||
time = datetime.strptime(data["time"], "%H:%M").time()
|
||||
print(time)
|
||||
Reference in New Issue
Block a user