bearer = ‘Bearer d1bd3b6d63e440a79844ab93fe1b0618c3a6d304e4744e3d9a97ba86842cda69’ # stf生成的訪問令牌
def get_info():
driver.get(‘http://10.8.1.219:7100/#!/devices’)
name = driver.find_element_by_name(“username”)
name.send_keys(“monkey2”)
email = driver.find_element_by_name(“email”)
email.send_keys(“monkey2@xxx.com”)
sleep(1)
login = driver.find_element_by_xpath(“//input[@type=‘submit’]”)
login.click()
sleep(1)
def get_devices_info():
url = “http://10.8.1.219:7100/api/v1/devices”
headers = {
'Authorization': bearer
}
response = requests.get(url, headers=headers)
devices = []
msg_dict = json.loads(response.text)
for item in msg_dict['devices']:
if "model" in item:
devices.append(
{"Name": item['model'], "version": item['version'],
"url": item['display']['url'].split("//")[1].split(":")[0] + ":" + str(
int(item['display']['url'].split("//")[1].split(":")[1]) + 1),
"using": item['using'], "present": item["present"], "owner": item['owner'], "serial": item['serial'],
"device_url": 'http://10.8.3.219:7100/#!/control/' + item['serial']})
return devices
def select_devices():
remove =
device_info =
return_device =
devices = get_devices_info()
print(devices)
if devices:
for element in devices:
if element[‘using’] == True or element[‘Name’] == ‘MI 4LTE’ or element[‘Name’] == ‘HRY-AL00a’ or element[
‘present’] == False:
remove.append(element)
for device in devices:
if device[“owner”] != None:
remove.append(device)
for item in devices:
if item not in remove:
device_info.append(item)
for ele in device_info:
if ele['Name'] == ' 1724':
return_device.append(ele)
return return_device
def apply_devices(serial):
url = f"http://10.8.1.219:7100/api/v1/user/devices/{serial}"
headers = {
‘Content-Type’: ‘application/json’,
‘Authorization’: bearer
}
payload = {“serial”: serial}
response = requests.post(url, headers=headers, data=payload)
print(response.text)
def remote_connect(serial):
url1 = f"http://10.8.1.219:7100/api/v1/user/devices/{serial}/remoteConnect"
headers = {
'Authorization': bearer
}
response = requests.post(url1, headers=headers)
print(response.text)
def delete_device(serial):
url = f"http://10.8.1.219:7100/api/v1/user/devices/{serial}"
headers = {
'Authorization': bearer
}
response = requests.delete(url, headers=headers)
print(response.text)