Ejemplo n.º 1
0
    def inner_wrapper(data=None, token=None, inner_headers=None):
        setLog = log()
        __ip, __port = globalEnvironment()
        url = __ip + __port + func()

        # 如果有token,则构造token请求头
        if token:
            headers["token"] = token
            headers["auth"] = token

        if inner_headers:
            headers.update(inner_headers)

        # 如果data是字典类型,则将data拼接成url
        if isinstance(data, dict):
            url = meger_url_with_params(url, data)
        # 或者如果data不是字典,并且不带token,那我认为data就是token
        elif data and not token:  # 因为上面有if isinstance(data,dict),所以这里隐藏带一个条件if not isinstance(data,dict)
            headers["token"] = data
            headers["auth"] = data
            data = None

        try:
            # 请求url,不校验证书,超时10s(不写默认120s)
            # 有请求头则发送请求头,没有则默认python自带的请求头
            if data:
                response = requests.get(url=url,
                                        headers=headers,
                                        verify=False,
                                        timeout=10)
            else:
                response = requests.get(url=url,
                                        headers=headers,
                                        verify=False,
                                        timeout=10)
            response.encoding = "UTF-8"
            result = None

            # 尝试解析成Json格式返回
            try:
                # ensure_ascii=False尝试汉字编码正常转换显示
                # result = json.loads(response.text,ensure_ascii=False)
                result = json.loads(response.text)
                return result
            # Text格式返回
            except:
                result = response.text
                return result
            finally:
                # setLog.info(r"接口访问成功,url:" + str(splitUrl(url)[0]))
                setLog.info(r"接口访问成功,url:" + url)
                setLog.info(r"请求头:" + str(headers))
                setLog.info(r"请求参:" + str(get_dict_by_url(url)))
                setLog.info(r"响应体:" + str(result))
        except:
            setLog.error(r"请求失败:" + url)
            setLog.info(r"请求头:" + str(headers))
            setLog.info(r"请求参:" + str(get_dict_by_url(url)))
Ejemplo n.º 2
0
    def __init__(self, database=None):

        # 数据库环境
        mysqlConfig = globalDataBase()

        self.host = mysqlConfig.get("host")
        self.port = mysqlConfig.get("port")
        self.user = mysqlConfig.get("user")
        self.password = mysqlConfig.get("password")
        self.charset = mysqlConfig.get("charset")
        if database:
            self.__database = database

        self.log = log()
Ejemplo n.º 3
0
def base(url, data, headers):
    setLog = log()

    # 如果是字典类型,则Json序列化
    if isinstance(data, dict):
        try:
            data = json.dumps(data)
        except:
            setLog.info("失败代码:data = json.dumps(data)")
            setLog.info("失败json序列化参数:" + data)

    # 发送post请求
    try:
        response = requests.post(url=url,
                                 data=data,
                                 headers=headers,
                                 verify=False,
                                 timeout=10)
        response = response.content.decode("unicode_escape")
        result = None

        # 判断返回能不能被字典序列化,如果能则返回字典
        try:
            result = json.loads(response)
            return result
        # 非Json的数据则返回text
        except:
            result = response
            return result
        finally:
            setLog.info("接口访问成功,url:" + url)
            setLog.info("请求头:" + str(headers))
            setLog.info("请求体:" + str(data))
            setLog.info("响应体:" + str(result))
    except:
        setLog.error("请求失败:" + url)
        setLog.error("失败请求头:" + str(headers))
        setLog.error("失败请求体:" + str(data))
Ejemplo n.º 4
0
 def __init__(self):
     self.codingFormat = "UTF-8"
     self.log = log()
Ejemplo n.º 5
0
def deleteData(userPhone):
    list = []
    videoList = []
    logName = log()
    """更新配置文件,返回连接配置文件对象"""
    database = parserMethod(dataPath() + "dataBase.ini")
    # database = parserMethod(dirPath.dataPath()+"dataBase.ini")

    # 创建连接qiaoku_user数据库对象
    userDb = odbc("qiaoku_user")
    # 创建连接qiaoku_user数据库对象
    videoDb = odbc("qiaoku_video")
    # 创建连接qiaoku_user数据库对象
    liveDb = odbc("qiaoku_live")
    # 创建连接qiaoku_user数据库对象
    homeDb = odbc("qiaoku_home")
    # 创建连接qiaoku_user数据库对象
    dataDb = odbc("qiaoku_data")

    # todo:用上面的方法获取所有需要初始化的表

    # 获取database.ini下配置的数据库所有表
    userTable = database.getOptions("userTable")
    videoTable = database.getOptions("videoTable")
    liveTable = database.getOptions("liveTable")
    homeTable = database.getOptions("homeTable")
    dataTable = database.getOptions("dataTable")

    logName.info("开始执行初始化配置")
    for i in range(1):
        user_id = [("624978533432688640", "随意填充")]
        # user_id = userDb.selectSQL("select user_id from tb_user_info where user_phone = %s"%userPhone)
        # 如果userId(元组)有数据则删除用户数据
        """user库"""
        if len(user_id) >= 1:
            user_id = user_id[0][0]
            # 如果删除token成功,返回1则写日志,如果删除token失败则返回None写入日志
            logName.info("token清理成功:%s" %
                         user_id) if rmToken(user_id) else logName.info(
                             "token清理失败:%s" % user_id)
            # 循环执行delete sql语句
            for i in userTable:
                # 如果存在该数据,返回True,执行数据删除
                if userDb.selectSQL("select * from %s where user_id = %s" %
                                    (i, user_id)):
                    try:
                        list.append(
                            userDb.commitSQL(
                                "delete from %s where user_id = %s" %
                                (i, user_id)))
                        time.sleep(0.01)
                    except:
                        logName.warning("初始化sql失败")
            """video库"""
            videoTuple = videoDb.selectSQL(
                "select video_id from tb_video where user_id = %s" % user_id)
            if len(videoTuple) >= 1:
                videoList = [i for i in videoTuple]
                # 遍历该用户下的video视频列表
                for video_id in videoList:
                    # 遍历video库的表,都根据用户的video视频删除
                    for i in videoTable:
                        # 如果存在该数据,返回True,执行数据删除
                        if videoDb.selectSQL(
                                "select * from %s where video_id = %s" %
                            (i, video_id[0])):
                            try:
                                list.append(
                                    videoDb.commitSQL(
                                        "delete from %s where video_id = %s" %
                                        (i, video_id[0])))
                                time.sleep(0.01)
                            except:
                                logName.warning("初始化sql失败")
            """live库"""
            room_id = liveDb.selectSQL(
                "select room_id from tb_player_info where user_id = %s" %
                user_id)
            if len(room_id) >= 1:
                for i in liveTable:
                    # 如果存在该数据,返回True,执行数据删除
                    if liveDb.selectSQL("select * from %s where room_id = %s" %
                                        (i, room_id[0][0])):
                        try:
                            list.append(
                                liveDb.commitSQL(
                                    "delete from %s where room_id = %s" %
                                    (i, room_id[0][0])))
                            time.sleep(0.01)
                        except:
                            logName.warning("初始化sql失败")
                for i in liveTable:
                    # 如果存在该数据,返回True,执行数据删除
                    if liveDb.selectSQL("select * from %s where user_id = %s" %
                                        (i, user_id)):
                        try:
                            list.append(
                                liveDb.commitSQL(
                                    "delete from %s where user_id = %s" %
                                    (i, user_id)))
                            time.sleep(0.01)
                        except:
                            logName.warning("初始化sql失败")
            """home库"""
            for i in homeTable:
                # 如果存在该数据,返回True,执行数据删除
                if homeDb.selectSQL("select * from %s where user_id = %s" %
                                    (i, user_id)):
                    try:
                        list.append(
                            homeDb.commitSQL(
                                "delete from %s where user_id = %s" %
                                (i, user_id)))
                        time.sleep(0.01)
                    except:
                        logName.warning("初始化sql失败")
            # 一个用户可能有多个video视频
            for video_id in videoList:
                for i in homeTable:
                    # 如果存在该数据,返回True,执行数据删除
                    if homeDb.selectSQL(
                            "select * from %s where video_id = %s" %
                        (i, video_id[0])):
                        try:
                            list.append(
                                homeDb.commitSQL(
                                    "delete from %s where video_id = %s" %
                                    (i, video_id[0])))
                            time.sleep(0.01)
                        except:
                            logName.warning("初始化sql失败")
            """data库"""
            for i in dataTable:
                # 如果存在该数据,返回True,执行数据删除
                if homeDb.selectSQL("select * from %s where user_id = %s" %
                                    (i, user_id)):
                    try:
                        list.append(
                            homeDb.commitSQL(
                                "delete from %s where user_id = %s" %
                                (i, user_id)))
                        time.sleep(0.01)
                    except:
                        logName.warning("初始化sql失败")
            # 一个用户可能有多个video视频
            for video_id in videoList:
                for i in dataTable:
                    # 如果存在该数据,返回True,执行数据删除
                    if dataDb.selectSQL(
                            "select * from %s where video_id = %s" %
                        (i, video_id[0])):
                        try:
                            list.append(
                                dataDb.commitSQL(
                                    "delete from %s where video_id = %s" %
                                    (i, video_id[0])))
                            time.sleep(0.01)
                        except:
                            logName.warning("初始化sql失败")

            # todo:这里是for循执行其他数据库SQL的地方,如上面for循环代码

            # 统计失败次数
                countFalse = len([i for i in list if not i])
                # 存在失败sql,写入日志
                if countFalse > 0:
                    logName.error("初始化sql失败数:%s" % countFalse)

                # 有失败的sql则返回False
                return True if countFalse == 0 else False
        else:
            # userDb.commitSQL("INSERT INTO `qiaoku_user`.`tb_user_info` "
            #              "(`id`, `user_id`, `qiaoku_id`, `nick_name`, `birthday`, `gender`, `avatar`, `avatar_large`, `user_phone`, `province`, `city`, `region`, `user_sign`, `user_origin`, `belong_back_user`, `udid`, `user_status`, `talent_mark`, `player_mark`, `total_publish_count`, `total_thumb_up_count`, `total_collection_count`, `user_follow_count`, `user_fans_count`, `binding_wx`, `binding_qq`, `del_flag`, `create_time`, `last_update_time`) "
            #              "VALUES ('1', '111111111111111111', '1111111111', 'EdenTestUser', NULL, '3', 'https://thirdwx.qlogo.cn/mmopen/vi_32/iblOuNxMNQoloaPo5xMM0acNt5jezgAyAIpnNDpRjJWDCxficmU4DPMEONuzpWor7FXOLDtYWIq8zOHHptpULUoQ/132', NULL, '12345678901', '', '', NULL, NULL, '0', NULL, '64d96dba-2e5f-4168-ade8-06652cbafeec', '1', '2', '1', NULL, NULL, NULL, NULL, NULL, '1', '2', '0', '2019-08-19 20:52:59', '2019-08-19 20:53:55');")
            # pass
            logName.warning("tb_user_info没有该用户数据,请确认是否存在绑定该手机号的用户")
        return True
Ejemplo n.º 6
0
    def inner_wrapper(data=None, token=None, inner_headers=None):
        setLog = log()
        __ip, __port = globalEnvironment()
        url = __ip + __port + func()

        headers["Content-Type"] = "application/json;charset=utf-8"

        # 如果有传token,则用token表单发送请求
        if token:
            headers["token"] = token
            headers["auth"] = token

        if inner_headers:
            headers.update(inner_headers)

        # 如果是字典类型,则Json序列化
        if isinstance(data, dict):
            try:
                # data = json.dumps(data, ensure_ascii=False)
                data = json.dumps(data)
                # pass
            except:
                setLog.info("失败代码:data = json.dumps(data)")
                setLog.info("失败json序列化参数:" + data)
                # pass

        # 有data并且data不是字典,并且不带token,那我认为data就是token
        elif data and not isinstance(data, dict) and not token:
            headers["token"] = data
            headers["auth"] = data
            data = None

        # 发送post请求
        try:
            # 有参post请求,带/不带token
            if data:
                response = requests.post(url=url,
                                         data=data,
                                         headers=headers,
                                         verify=False,
                                         timeout=20)
            # 无参post请求,带/不带token
            else:
                response = requests.post(url=url,
                                         headers=headers,
                                         verify=False,
                                         timeout=10)
            response.encoding = "UTF-8"
            result = None

            # 判断返回能不能被字典序列化,如果能则返回字典
            try:
                result = json.loads(response.text)
                return result
            # 非Json的数据则返回text
            except:
                result = response.text
                return result
            finally:
                setLog.info("接口访问成功,url:" + url)
                setLog.info("请求头:" + str(headers))
                if data not in headers.values():
                    setLog.info("请求体:" + str(data))
                setLog.info("响应体:" + str(result))
        except:
            setLog.error("请求失败:" + url)
            setLog.error("失败请求头:" + str(headers))
            if data not in headers.values():
                setLog.info("请求体:" + str(data))
Ejemplo n.º 7
0
 def __init__(self, startTime="09:00"):
     self.startTime = startTime
     self.log = log()
Ejemplo n.º 8
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import requests, json
from src.utils.Log import log
from src.utils.StringUtils import get_dict_by_url, meger_url_with_params
# from src.utils import RequestMethod
from src.utils.HttpUtils import choice

setLog = log()


def send_get(url, params_dict=None, body_dict=None, headers_dict=None):
    result = None

    if not params_dict:
        params_dict = get_dict_by_url(params_dict)
    if not body_dict or not headers_dict:
        body_dict = {}
        params_dict = {}
    try:
        # 请求url,不校验证书,超时10s(不写默认120s)
        # 有请求头则发送请求头,没有则默认python自带的请求头
        response = choice.get('GET')(url, params_dict, body_dict, headers_dict)
        response = response.text
        # response = response.content.decode("unicode_escape")

        # 尝试解析成字典对象返回
        try:
            result = json.loads(response)
            return result
Ejemplo n.º 9
0
 def __init__(self, filename, file_suffix=".xls"):
     self.filename = filename + file_suffix
     self.log = log()