kkk2z1 commited on
Commit
6c9ec7b
·
verified ·
1 Parent(s): 5f68f86

Create kitool.py

Browse files
Files changed (1) hide show
  1. module/kitool.py +71 -0
module/kitool.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #汎用ツール。
2
+
3
+ import os
4
+ import time
5
+ from datetime import datetime
6
+ import json
7
+ import traceback
8
+ from colorama import Fore, Back, Style, init
9
+
10
+ #===ツール===
11
+ def log(msg, msg_type):
12
+ try:
13
+ init()
14
+ time_datetime = datetime.now()
15
+ if msg_type == 1: # 通常ログ(緑)
16
+ print(f"{time_datetime}{Fore.GREEN}[log]: {msg}")
17
+ elif msg_type == 2: # 警告(黄色)
18
+ print(f"{time_datetime}{Fore.YELLOW}[warn]: {msg}")
19
+ elif msg_type == 3: # エラー(赤)
20
+ print(f"{time_datetime}{Fore.RED}[error]: {msg}")
21
+ elif msg_type == 4: # エラー(エラー部分のトレースバック付き。)
22
+ print(f"{time_datetime}{Fore.RED}[error]: {msg}")
23
+ print(Fore.RED)
24
+ traceback.print_exc()
25
+ except Exception as e:
26
+ time_datetime = datetime.now()
27
+ print(f"{time_datetime}[error]:log()関数にてエラーあり。:{e}")
28
+
29
+ def count_down(sec,count_down_msg):
30
+ try:
31
+ START_TIME = sec
32
+ while START_TIME > 0:
33
+ print(f"{count_down_msg}{START_TIME}秒",)
34
+ START_TIME = START_TIME - 1
35
+ time.sleep(1)
36
+
37
+ except Exception as e:
38
+ time_datetime = datetime.now()
39
+ print(f"{time_datetime}[error]:count_down()関数にてエラーあり:{e}")
40
+
41
+ def hash_time(hash):
42
+ try:
43
+ loop = hash
44
+ rand_hash = random.randint(0, 75)
45
+ now_hash = hash(f"{rand_hash}")
46
+ hash_s_time = time.time()
47
+ while loop > 0
48
+ now_hash = hash(f"{now_hash}")
49
+ hash_e_time = time.time()
50
+ hash_time = hash_s_time - hash_e_time
51
+ return hash_time
52
+ except Exception as e:
53
+ time_datetime = datetime.now()
54
+ print(f"{time_datetime}[error]:hash_time()関数にてエラーあり:{e}")
55
+
56
+
57
+ #===使い方===
58
+ #log(msg, msg_type):
59
+ # ログ出力。
60
+ # log("出力させたいログメッセージ",ログの種類):
61
+ # 指定できるログの種類:
62
+ # 1=通常のログ
63
+ # 2=警告
64
+ # 3=エラー
65
+ # 4=エラー(トレースバック付き)
66
+ #count_down(sec,count_down_msg):
67
+ # 指定された秒数カウントダウンをする。
68
+ # count_down(カウントする秒数,残り秒数の前に置く文字列):
69
+ #hash_time(hash):
70
+ # 指定されたから回数だけhashを行い処理にかかった時間を出力する。
71
+ # hash_time(hashする回数)