-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathutils.py
48 lines (35 loc) · 1.09 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from datetime import datetime
import json
from flask import make_response, Response
def info(log):
print(f"[Info] {datetime.now().strftime('[%Y-%m-%d %H:%M:%S]')} " + log)
def infon(log):
print(f"\n[Info] {datetime.now().strftime('[%Y-%m-%d %H:%M:%S]')} " + log)
def warning(log):
print(f"[Warning] {datetime.now().strftime('[%Y-%m-%d %H:%M:%S]')} " + log)
def error(log):
print(f"[Error] {datetime.now().strftime('[%Y-%m-%d %H:%M:%S]')} " + log)
def format_dict(dic) -> Response:
'''
列表 -> 格式化 json
@param dic: 列表
'''
# return jsonify(dic, ensure_ascii = False)
response = make_response(
json.dumps(dic, indent=4, ensure_ascii=False, sort_keys=False, separators=(', ', ': '))
)
response.mimetype = 'application/json'
return response
def reterr(code: int, message: str) -> str:
'''
返回错误信息 json
:param code: 代码
:param message: 消息
'''
ret = {
'success': False,
'code': code,
'message': message
}
error(f'{code} - {message}')
return format_dict(ret)