fisrt commit

This commit is contained in:
peterlu14
2021-12-20 14:52:55 +08:00
parent af68735608
commit 2341ef2e75
297 changed files with 89609 additions and 61 deletions
+57
View File
@@ -0,0 +1,57 @@
import requests
import json
from . import API_URL
from .auth import AuthAPI
class ControllerAPI():
@staticmethod
def create(attrs):
try:
ret = requests.post(API_URL + 'api/controller/create', attrs, headers= AuthAPI.get_key())
if ret.status_code == 200:
return True
except requests.exceptions.ConnectionError as e:
print('create controller fail', e)
return False
@staticmethod
def getByMac(mac_address):
try:
ret = requests.get(API_URL + 'api/controller/get_by_mac/' + mac_address, headers= AuthAPI.get_key())
if ret.status_code == 200:
return ret.json()
except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
print('get controller fail', e)
return []
@staticmethod
def getAll():
try:
api_key = AuthAPI.get_key()
ret = requests.get(API_URL + 'api/controller/get/all', headers= AuthAPI.get_key())
if ret.status_code == 200:
return ret.json()
except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
print('get all controllers fail', e)
return []
@staticmethod
def updateByAttrs(attrs = None, values = None , datas:dict = None):
try:
ret = requests.post(API_URL + 'api/controller/update_by_attr/' + str(attrs) + '/' + str(values), datas, headers= AuthAPI.get_key())
if ret.status_code == 200:
return True
except requests.exceptions.ConnectionError as e:
print('update controller fail', e)
return False
# def existController(self, mac_address):
# try:
# res = self._requests.get('http://' + api_url + ':3000/api/controller/get_by_mac/' + mac_address, headers= self._header, timeout = 3)
# if len(res.json()) > 0:
# return True
# return False
# except (requests.exceptions.ConnectionError, json.decoder.JSONDecodeError) as e:
# print('existController', e)
# pass