add: time
This commit is contained in:
@@ -1,25 +1,36 @@
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
import socket
|
import socket
|
||||||
|
import datetime
|
||||||
|
|
||||||
machine_name = socket.gethostname()
|
machine_name = socket.gethostname()
|
||||||
url = "http://192.168.50.27:5000/lookup"
|
url = "http://192.168.50.27:5000/lookup"
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"name": machine_name,
|
"name": machine_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
data = json.dumps(payload).encode("utf-8")
|
def get_data():
|
||||||
|
data = json.dumps(payload).encode("utf-8")
|
||||||
|
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
url,
|
url,
|
||||||
headers={"Content-Type": "application/json"},
|
headers={"Content-Type": "application/json"},
|
||||||
data=data,
|
data=data,
|
||||||
method="POST"
|
method="POST"
|
||||||
)
|
)
|
||||||
|
|
||||||
with urllib.request.urlopen(req, timeout=10) as response:
|
try:
|
||||||
data = response.read()
|
with urllib.request.urlopen(req, timeout=10) as response:
|
||||||
json_data = json.loads(data)
|
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