def __init__(self): self.path_login = find_path() + '/data' + "/login.xlsx" self.path_project = find_path() + '/data' + "/projects.xlsx" self.path_prd = find_path() + '/data' + "/products.xlsx" self.token = EX.get_key_value(self.path_login, get_login_sheet_name(), "access_token") self.headers = {"Content-Type": "application/json", "Access-Token": self.token} self.host = get_host() self.port = ""
def __init__(self): self.path_datapoint = find_path() + '/data' + '/datapoint.xlsx' self.path_login = find_path() + '/data' + "/login.xlsx" self.value_list = EX.load_data(self.path_datapoint,"Sheet3") self.token = EX.get_key_value(self.path_login, get_login_sheet_name(), "access_token") self.headers = {"Content-Type": "application/json", "Access-Token": self.token} self.host = get_host() self.port = ""
def __init__(self): self.path_alarm = find_path() + '/data' + '/alarm.xlsx' self.path_login = find_path() + '/data' + '/login.xlsx' self.value_list = EX.load_data(self.path_alarm, "告警规则") self.token = EX.get_key_value(self.path_login, get_login_sheet_name(), "access_token") self.headers = {"Content-Type": "application/json", "Access-Token": self.token, "Api-Version": "2"} self.host = get_host() self.port = ""
def __init__(self): self.path_login = find_path() + '/data' + "/login.xlsx" self.path_maintenance = find_path() + '/data' + "/maintenance.xlsx" self.token = EX.get_key_value(self.path_login, get_login_sheet_name(), "access_token") self.headers = {"Content-Type": "application/json", "Access-Token": self.token} self.host = get_host() self.port = "" self.result = None self.projectid = ''
def login(sheet_name=login_sheet): path = find_path() + '/data' + "/login.xlsx" host = get_host(sheet_name) port = "" api = EX.get_key_value(path,sheet_name,"api") login_url = host + port + api username = EX.get_key_value(path,sheet_name,"username") password = EX.get_key_value(path,sheet_name,"password") data = {"account": username, "password": password} header = {"Content-Type": "application/json"} print(login_url) res = requests.post(login_url, json=data, headers=header) if res.status_code == 200: print("登录%s成功" % sheet_name) else: print("登录%s失败" % sheet_name) change_cont = eval(res.text) token = change_cont["access_token"] EX.write_key_value(path, sheet_name, "access_token", token)
def __init__(self): self.path_device = find_path() + '/data' + '/devices.xlsx' self.path_login = find_path() + '/data' + "/login.xlsx" self.path_product = find_path() + '/data' + "/products.xlsx" self.device_info = EX.load_data(self.path_device, "设备注册") self.pid_lists = EX.load_data_by_column(self.path_product, "自动导出产品信息", "pid") # self.pid_lists = EX.load_data_by_column(self.path_product, "Sheet2") self.token = EX.get_key_value(self.path_login, get_login_sheet_name(), "access_token") self.headers = { "Content-Type": "application/json", "Access-Token": self.token } self.host = get_host() self.port = ""
def login_with_api(api_addr, user, pwd): path = find_path() + '/data' + "/login.xlsx" api = EX.get_key_value(path, get_login_sheet_name(), "api") if api_addr == '1': api_addr = iot_api elif api_addr == '2': api_addr = release_api login_url = api_addr + api data = {"account": user, "password": pwd} header = {"Content-Type": "application/json"} try: res = requests.post(login_url, json=data, headers=header) if res.status_code == 200: change_cont = eval(res.text) token = change_cont["access_token"] EX.write_key_value(path, get_login_sheet_name(), "host", api_addr) EX.write_key_value(path, get_login_sheet_name(), "access_token", token) return True else: return False except: print('traceback.format_exc():\n%s' % traceback.format_exc()) return False
def get_host(sheet=login_sheet): path = find_path() + '/data' + "/login.xlsx" host = EX.get_key_value(path, sheet, "host") return host