File size: 2,442 Bytes
49cba05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#汎用ツール。

import os
import time
from datetime import datetime
import json
import traceback
from colorama import Fore, Back, Style, init

#===ツール===
def log(msg, msg_type):
    try:
        init()
        time_datetime = datetime.now()
        if msg_type == 1:  # 通常ログ(緑)
            print(f"{time_datetime}{Fore.GREEN}[log]: {msg}")
        elif msg_type == 2:  # 警告(黄色)
            print(f"{time_datetime}{Fore.YELLOW}[warn]: {msg}")
        elif msg_type == 3:  # エラー(赤)
            print(f"{time_datetime}{Fore.RED}[error]: {msg}")
        elif msg_type == 4:  # エラー(エラー部分のトレースバック付き。)
            print(f"{time_datetime}{Fore.RED}[error]: {msg}")
            print(Fore.RED)
            traceback.print_exc()
    except Exception as e:
        time_datetime = datetime.now()    
        print(f"{time_datetime}[error]:log()関数にてエラーあり。:{e}")

def count_down(sec,count_down_msg):
    try:
        START_TIME = sec
        while START_TIME > 0:
            print(f"{count_down_msg}{START_TIME}秒",)
            START_TIME = START_TIME - 1
            time.sleep(1)
    
    except Exception as e:
        time_datetime = datetime.now()    
        print(f"{time_datetime}[error]:count_down()関数にてエラーあり:{e}")

def hash_time(hash):
    try:
        loop = hash
        rand_hash = random.randint(0, 75)
        now_hash = hash(f"{rand_hash}")
        hash_s_time = time.time()
        while loop > 0
            now_hash = hash(f"{now_hash}")
        hash_e_time = time.time()
        hash_time = hash_s_time - hash_e_time
        return hash_time
    except Exception as e:
        time_datetime = datetime.now()    
        print(f"{time_datetime}[error]:hash_time()関数にてエラーあり:{e}")


#===使い方===
#log(msg, msg_type): 
#   ログ出力。  
#   log("出力させたいログメッセージ",ログの種類):
#   指定できるログの種類: 
#       1=通常のログ
#       2=警告
#       3=エラー
#       4=エラー(トレースバック付き)
#count_down(sec,count_down_msg):
#   指定された秒数カウントダウンをする。
#   count_down(カウントする秒数,残り秒数の前に置く文字列):
#hash_time(hash):
#    指定されたから回数だけhashを行い処理にかかった時間を出力する。
#    hash_time(hashする回数)