一、jsonpath模块
1 import jsonpath 2 3 CHJ = { 4 "money":19000, 5 "house":{ 6 "beijing":["三环","四环","五环"], 7 "shanghai":["静安区","浦东新区"], 8 "house":{ 9 "beijing":["三环","四环","五环"], 10 "shanghai":["静安区","浦东新区"] 11 } 12 }, 13 "car":["bmw",'benz','audi','byd'], 14 "pets":[ 15 {"name":"张三","type":"dog"}, 16 {"name":"lisi","type":"nan"}, 17 {"name":"Test","type":"xi"}, 18 {"name":"zhuge","type":"bei"}, 19 ] 20 } 21 #jsonpath 22 #$.pets[0].type 23 result = jsonpath.jsonpath(CHJ,"$.pets[3].type") 24 #result = jsonpath.jsonpath(CHJ,"$..house") 25 print(result)
二、写入日志模块
1 from loguru import logger 2 import sys 3 4 logger.remove() #把默认的配置删掉 5 fmt = '[{time}][{level}][{file.path}:line:{line}:function_name:{function}] ||msg={message}' 6 # 7 logger.add(sys.stdout,format=fmt,level="ERROR") 8 logger.add("wsc.log",format=fmt,level="DEBUG",encoding="utf-8",enqueue=True,rotation="1 day",retention="7 days") 9 #enqueue 异步写入 10 #系统标准输出 11 # rotation可以设置大小,超过多大就产生一个新文件 1 kb ,500 m ,1 g 12 # rotation可以多长时间,1 day 1 hour 13 # rotation几点创建新文件,00:00 1:00 14 15 # retention = 7 days #多长时间后会删除以前产生的日志,当前的日志不会受影响 16 17 logger.error("=======错误日志======") 18 logger.warning("======警告日志======") 19 logger.info("======正常提示日志======") 20 logger.debug("======打印日志较多======")
三、加密模块
1. base64加解密
1 import base64 2 print("======加密=================================") 3 s = "chj123CHJ963" 4 result = base64.b64encode(s.encode()).decode() 5 print(result) 6 print("======解密=================================") 7 s1 = "Y2hqMTIzQ0hKOTYz" 8 result = base64.b64decode(s1).decode() 9 print(result)
2. md5加密
1 import hashlib 2 3 j = "123456" 4 bj = j.encode() 5 # m = hashlib.md5( bs ) 6 j = hashlib.sha256( bj ) 7 # m = hashlib.sha512( bs ) 8 # m = hashlib.sha224( bs ) 9 print(j.hexdigest())
3. 加密加盐
1 import hashlib 2 3 #加盐 4 s = "123456" + "@¥gbg3t23!#" 5 bs = s.encode() 6 m = hashlib.sha256( bs ) 7 def my_md5(s,salt=""): 8 new_s = str(s) + salt 9 m = hashlib.md5(new_s.encode()) 10 return m.hexdigest() 11 print(m.hexdigest())