deviceresource.py 977 Bytes
# -*- coding: utf-8 -*-
# @Time    :  2020/12/11 17:48
# @Author  :  Young Lee
# @Email   :  young_lee2017@163.com

from jumppage import jump_page


def device_resource(driver):
    """获取分析资源数量

    :return: {"total": total_resource, "free": free_resource}
    """
    jump_page(driver, "系统运维", "设备管理")
    try:
        total_element = driver.find_element_by_xpath("//span[text()='分析资源数:']/following-sibling::span")
        free_element = driver.find_element_by_xpath("//span[text()='离线资源数:']/following-sibling::span")
        total_resource = int(total_element.text)
        free_resource = int(free_element.text)
        return {"total": total_resource, "free": free_resource}
    except Exception:
        return {"total": 0, "free": 0}


if __name__ == "__main__":
    from unitinit import *
    from login import login_fx
    login_fx(driver, login_url, user, passwd)
    print(device_resource(driver))
    driver.quit()