zoukankan      html  css  js  c++  java
  • 模块(写日志、jsonpath、加密)

    1.写日志模块

    from loguru import logger
    import sys
    
    logger.remove() #把默认的配置删掉
    
    fmt = '[{time}][{level}][{file.path}:line:{line}:function_name:{function}] ||msg={message}'
    logger.add(sys.stdout,format=fmt,level="DEBUG")
    logger.add("wsc.log",format=fmt,level="DEBUG",encoding="utf-8",enqueue=True,rotation="1 day",retention="7 days")
    #enqueue 异步写入
    #系统标准输出
    # rotation可以设置大小,超过多大就产生一个新文件 1 kb ,500 m ,1 g
    # rotation可以多长时间,1 day   1 hour
    # rotation几点创建新文件,00:00  1:00
    
    # retention = 7 days #多长时间后会删除以前产生的日志,当前的日志不会受影响
    
    logger.debug("我是debug")  #打印信息比较多
    logger.info("我是info")  #正常的提示信息
    logger.warning("warning") #警告
    logger.error("error") #错误

    2.jsonpath模块

    import jsonpath
    
    wsc = {
        "money":19000,
        "house":{
            "beijing":["三环","四环","五环"],
            "shanghai":["静安区","浦东新区"]
        },
        "car":["bmw",'benz','audi','byd'],
        "pets":[
            {"name":"xiaohei","type":"dog"},
            {"name":"xiaobai","type":"cat"},
            {"name":"xiaofen","type":"cat"},
            {"name":"xiaolan","type":"dog"},
        ]
    }
    
    #$.pets[0].type
    #result  = wsc["pets"][0]["type"] #原有的方法获取
    #result  = jsonpath.jsonpath(wsc,"$.pets[0].type")
    #result  = jsonpath.jsonpath(wsc,"$..car")
    result  = jsonpath.jsonpath(wsc,"$..beijing")
    print(result)

     3.加密模块

    import hashlib
    
    s = "123456" + "@¥gbg3t23!#"
    bs = s.encode()#把s从unicode编码方式转换成utf-8的编码方式;bs.decode('utf-8') # 解码成unicode编码
    m = hashlib.md5( bs )
    m = hashlib.sha256( bs )
    m = hashlib.sha512( bs )
    m = hashlib.sha224( bs )
    print(m.hexdigest())
    
    #id mingwen      miwen
    # 1   wsc12345   4f6c35f22a199f9189ccea52fffed3b4
    
    #加盐
    
    def my_md5(s,salt=""):
        new_s = str(s) + salt
        m = hashlib.md5(new_s.encode())
        return m.hexdigest()
    
    import base64
    s = "wanshu、+@#%chengsdgsdgsdgsdgssgsgsg"
    result = base64.b64encode(s.encode()).decode()
    print(result)
    
    #d2Fuc2h1Y2hlbmdzZGdzZGdzZGdzZGdzc2dzZ3Nn
    
    s1 = "d2Fuc2h1Y2hlbmdzZGdzZGdzZGdzZGdzc2dzZ3Nn"
    result = base64.b64decode(s1).decode()
    print(result)
    加油
  • 相关阅读:
    oracle单表选择率(selectivity)——计算执行计划的基数
    不该建索引及不走索引的原因
    SQL语言:DDL/DML/DQL/DCL
    HDU 4521 间隔》=1的LIS 线段树+dp
    九度OnlineJudge之1032:ZOJ
    FileUpload的使用案例
    【C++第三课】---新的关键字
    Clash of Clans(COC)资源压缩解密
    jquery第一期:运行第一个jquery
    Java 的zip压缩和解压缩
  • 原文地址:https://www.cnblogs.com/huahuacheng/p/14320980.html
Copyright © 2011-2022 走看看