示例#1
0
 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 = ""
示例#2
0
 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 = ""
示例#3
0
 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 = ""
示例#4
0
 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 = ''
示例#5
0
 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 = ""
示例#6
0
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)
示例#7
0
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
示例#8
0
    else:
        print("未找到:" + key)
        print(ws.cell(row=2, column=1).value)
        return None


#
# def get_key_values(file_path, sheet_name):
#     '''
#     获取键值
#     :param file_path:
#     :param sheet_name:
#     :param key:
#     :return: key
#     '''
#     wb = openpyxl.load_workbook(file_path)
#     ws = wb[sheet_name]
#     lists = []
#     for i in range(1, ws.max_row+1):
#         lists.append(ws.cell(row=i, column=1).value)
#     return lists

if __name__ == '__main__':
    # path = find_path() + '/data' + "/login.xlsx"
    # path = find_path() + '/data' + "/products.xlsx"
    # path = find_path() + '/data' + "/devices.xlsx"
    # path = find_path() + '/data' + "/parking.xlsx"
    path = find_path() + '/data' + "/projects.xlsx"
    # print(row_length(path, "Sheet1"))
    print(load_data_by_column(path, "项目信息", "项目类型"))
示例#9
0
# coding = utf-8
from common.myconfigparser import MyConfigParser
from common.function import find_path, get_now_date

path = find_path() + '/data' + '/devices_online' + get_now_date() + '.ini'
cf = MyConfigParser()


def get_from_ini(fpath, section, option):
    cf.read(fpath)
    value = cf.get(section, option)
    return value


def write_to_ini(section, option, name, fpath=path):
    try:
        cf.read(fpath)
        tem = cf.has_section(section)
        if not tem:
            cf.add_section(section)
            cf.set(section, option, name)
            cf.write(open(fpath, "w"))
        else:
            cf.set(section, option, name)
            cf.write(open(fpath, "w"))
    except Exception as msg:
        print(msg)


if __name__ == '__main__':
    write_to_ini("DEVICE4", "PRODUCTNAME", "xiaofangwenyaben")
示例#10
0
def get_host(sheet=login_sheet):
    path = find_path() + '/data' + "/login.xlsx"
    host = EX.get_key_value(path, sheet, "host")
    return  host
示例#11
0
#     wb.save(file_path)


# def get_key_values(file_path, sheet_name):
#     '''
#     获取键值
#     :param file_path:
#     :param sheet_name:
#     :param key:
#     :return: key
#     '''
#     wb = openpyxl.load_workbook(file_path)
#     ws = wb[sheet_name]
#     lists = []
#     for i in range(1, ws.max_row+1):
#         lists.append(ws.cell(row=i, column=1).value)
#     return lists


if __name__ == '__main__':
    path = find_path() + '/data' + "/login.xlsx"
    # path = find_path() + '/data' + "/products.xlsx"
    # path = find_path() + '/data' + "/devices.xlsx"
    # path = find_path() + '/data' + "/parking.xlsx"
    # path = find_path() + '/data' + "/projects.xlsx"
    # print(row_length(path, "Sheet1"))
    # print(load_data_by_column(path, "项目信息","项目类型"))
    # write_possible_judge(path, "Sheet1")