zoukankan      html  css  js  c++  java
  • AppUi自动化框架tools.py代码

    import pymysql
    import redis
    import requests
    import hashlib
    import os
    from lib.path import APP_REPORT


    class MyMysql(object):
    def __init__(self, host, port, user, password, db, charset='utf8'):
    self.__host = host
    self.port = port
    self.user = user
    self.password = password
    self.db = db
    self.charset = charset
    self.__get_cur()

    def __get_cur(self):
    try:
    self.con = pymysql.connect(host=self.__host, port=self.port, user=self.user,
    password=self.password, db=self.db, charset=self.charset)
    except Exception as e:
    print('这里出错了,错误信息是:%s' % e)
    else:
    self.cur = self.con.cursor()

    def select_sql(self, sql):
    try:
    self.cur.execute(sql)
    except Exception as e:
    print('sql执行失败:%s' % e)
    else:
    return self.cur.fetchall()

    def other_sql(self, sql):
    try:
    self.cur.execute(sql)
    except Exception as e:
    print('sql执行失败:%s' % e)
    else:
    self.con.commit()

    def close(self):
    self.cur.close()
    self.con.close()


    class MyRedis(object):
    def __init__(self, host, port, password):
    self.pool = redis.ConnectionPool(host=host, port=port, password=password)
    self.r = redis.Redis(connection_pool=self.pool)

    def get(self, k):
    return self.r.get(k)

    def set(self, k, v):
    self.r.set(k, v)


    def my_request(method, url, data=None, headers=None, files=None): # 返回结果函数
    try:
    if method.upper() == 'GET':
    r = requests.get(url, data, headers=headers, files=files).json()
    else:
    r = requests.post(url, data, headers=headers, files=files).json()
    except Exception as e:
    return '出错了,错误是:%s' % e
    return r


    def my_md5(st): # 加密函数
    secret_key = 'st90dsf43ert'
    st = str(st) + secret_key
    md = hashlib.md5()
    md.update(st.encode())
    return md.hexdigest()


    def get_new_report():
    all_report = os.listdir(APP_REPORT)
    file_name = all_report[1]
    abs_path = os.path.join(APP_REPORT, file_name)
    return abs_path


    def remove_report():
    all_report=os.listdir(APP_REPORT)
    for report in all_report:
    if report.endswith('.html'):
    abs_path = os.path.join(APP_REPORT, report)
    os.remove(abs_path)

    # my_mysql = MyMysql(**MYSQL_INFO)
    # my_redis = MyRedis(**REDIS_INFO)
  • 相关阅读:
    条件判断和循环
    list 和tuple的使用
    python的五大数据类型
    简单的一个程序,猜字游戏
    redhat7 nfs的配置以及auto自动挂载
    nmcli添加网卡 并且修改设备名字 添加IP地址
    RHEL7 系统ISCSI存储环境搭建
    Java分布式锁
    24个Jvm面试题总结及答案
    最新天猫3轮面试题目:虚拟机+并发锁+Sql防注入+Zookeeper
  • 原文地址:https://www.cnblogs.com/laosun0204/p/9748985.html
Copyright © 2011-2022 走看看