i got my swag back
This commit is contained in:
+19
-8
@@ -1,28 +1,39 @@
|
||||
import sys
|
||||
sys.path = [p for p in sys.path if 'Python27' not in p] # uglyfix
|
||||
from urllib import request
|
||||
import json
|
||||
import socket
|
||||
from datetime import datetime
|
||||
import subprocess
|
||||
import time
|
||||
import requests
|
||||
|
||||
DEFAULT_SHUTDOWN = "21:00"
|
||||
|
||||
LAST_VALUE = 0
|
||||
|
||||
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:
|
||||
response = requests.post(url, json=payload, timeout=10)
|
||||
response.raise_for_status()
|
||||
json_data = response.json()
|
||||
print(json_data)
|
||||
return json_data
|
||||
except requests.RequestException:
|
||||
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
|
||||
|
||||
def to_seconds(t):
|
||||
|
||||
Reference in New Issue
Block a user