Exemplo n.º 1
0
def loginUrlSign(path, dateline, lasttime, second, meter):
    str1 = path[:path.index('.')] if '.' in path else path
    str2 = str(dateline)
    str3 = "{}{}{}".format(lasttime, second, meter)
    print(str1, str2, str3)
    str0 = "raowenyuan{}joy{}the{}run".format(str1.lower(), str2, str3.lower())
    return MD5(str0).lower()
Exemplo n.º 2
0
def write_to_mysql(_data):
    """
    向Mysql中写数据
    :param _data: 单条Json格式数据
    :return:
    """
    redis = Redis().get_instance()
    _id = _data['coding']
    redis_hash_key = REDIS_HASH_KEY_PREFIX + _id
    mysql_hash_key = MYSQL_HASH_KEY_PREFIX + _id

    hash_value = _id + MD5.obj_md5(_data)

    redis.set(_id, json.dumps(_data))  # redis中的对象
    redis.set(redis_hash_key, hash_value)  # redis中对象的特征值

    __m_exe = MapperExecute()
    if redis.exists(mysql_hash_key):
        if operator.eq(redis.get(mysql_hash_key), hash_value):
            ret = __m_exe.update_by_pk(BaseInfo(), _data)
            logger.info('更新影响行数:' + str(ret) + '[' + _id + ']')
        else:
            logger.debug('数据库与爬取内容相同:' + '[' + _id + ']:' + str(_data))
    else:
        __m_exe.insert_selective(BaseInfo(), _data)
        logger.info('新增项数据:' + '[' + _id + ']')
    redis.set(mysql_hash_key, hash_value)
Exemplo n.º 3
0
def __get_signature(params, uid, sid, salt):
    if not uid: # uid == 0 or ''
        uid = sid = ''
    return MD5("{paramsString}{salt}{uid}{sid}".format(
            paramsString = "".join("".join((k, str(v))) for k, v in sorted(params.items())),
            salt = salt,
            uid = str(uid),
            sid = sid,
        )).upper()
Exemplo n.º 4
0
    def __get_msgAbs(self, payload):
        """ iaaa 鉴权算法
            signature = MD5("&[key1]=[value1]&[key2]=[value2]..." + AppSecret) # key 按字典序排列

            Args:
                payload      dict    post 请求的 payload
            Returns:
                signature    str     签名
        """
        return MD5("&".join("=".join(item) for item in sorted(payload.items())) + self.AppSecret)  # TreeMap 按 keys 升序遍历
Exemplo n.º 5
0
 def __get_signature(cls, params, uid, sid, salt):
     """ 两个通用 signature 的函数模板
     """
     if not uid:  # uid == 0 or ''
         uid = sid = ''
     preHashString = "{paramsString}{salt}{uid}{sid}".format(
         paramsString="".join("".join((k, str(v)))
                              for k, v in sorted(params.items())),
         salt=salt,
         uid=str(uid),
         sid=sid,
     )
     # cls.logger.debug(preHashString)
     return MD5(preHashString).upper()
Exemplo n.º 6
0
    def login(self):
        """ 登录 API
        """
        params = {
                "username": self.userName,
                "pwd": MD5(self.password).upper(),
            }
        respJson = self.get("//user/login/normal", params, auth=self.auth.reload(params))

        self.sid = respJson['data']['sid']
        self.uid = int(respJson['data']['user']['uid'])

        json_dump(self.Cache_LoginInfo, {"sid": self.sid, "uid": self.uid}) # 缓存新的登录信息
        self.__update_loginInfo()
Exemplo n.º 7
0
    def login_url_sign(cls, path, dateline, strAry):
        """ loginUrlSign 用于上传记录
            描述了请求 url 的 path,请求时间,关键请求参数

            Args:
                path        str     请求路径
                dateline    int     类似与时间戳
                strAry      list    关键请求参数
        """
        return MD5("raowenyuan{path}joy{timestamp}the{keys}run".format(
            path=path[:path.index('.')].lower()
            if '.' in path else path.lower(),
            timestamp=str(dateline),
            keys="".join(map(str, strAry)).lower(),
        )).lower()
Exemplo n.º 8
0
def loginUrlSign(path, dateline, strAry):
    return MD5("raowenyuan{path}joy{timestamp}the{keys}run".format(
        path=path[:path.index('.')].lower() if '.' in path else path.lower(),
        timestamp=str(dateline),
        keys="".join(map(str, strAry)),
    ))
Exemplo n.º 9
0
 def save(imgBytes):
     file = MD5(imgBytes) + ".jpg"
     path = os.path.join(Download_Dir, file)
     with open(path, "wb") as fp:
         fp.write(imgBytes)
     print("get captcha " + file)