-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdebugger.py
59 lines (50 loc) · 1.46 KB
/
debugger.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
49
50
51
52
53
54
55
56
57
58
59
import requests
import os
import json
import time
import sys
from dotenv import load_dotenv
load_dotenv()
class Debugger(object):
"""
Class for debugger print
"""
def __init__(self):
pass
@staticmethod
def error_print(msg, debug=True):
if debug:
print('[error]' + msg)
@staticmethod
def warn_print(msg, debug=True):
if debug:
print('[warning]' + msg)
@staticmethod
def debug_print(msg, debug=True):
if debug:
print('[debug]' + msg + '\r', end='')
sys.stdout.flush()
@staticmethod
def info_print(msg):
print('[info]' + msg)
@staticmethod
def time_print(msg, begin, profiling=False):
if profiling:
assert isinstance(begin, type(time.time())
), 'invalid begin time {}'.format(begin)
print('[info]{}, elapsed for {:.2f}s'.format(
msg, time.time() - begin))
@staticmethod
def dc_print(msg, debug=True):
data = {
'content': msg
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(os.getenv('DC_WEBHOOK'),
data=json.dumps(data), headers=headers)
if response.status_code == 204:
print("訊息已成功發送到Discord Webhook!")
else:
print("發送訊息到Discord Webhook時出現錯誤!")