Renecto commited on
Commit
70790e9
1 Parent(s): 940faa3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -4,10 +4,30 @@ from datetime import datetime
4
  import pytz
5
  import psutil
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  def greet(name):
9
  start = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
10
  time.sleep(1)
 
11
  end = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
12
  return f"[{name}] {start} ~ {end}"
13
 
 
4
  import pytz
5
  import psutil
6
 
7
+ def get_cpu_usage_visual():
8
+ # 各コアのCPU使用率を取得
9
+ cpu_usages = psutil.cpu_percent(interval=1, percpu=True)
10
+ visual_line = ""
11
+
12
+ for usage in cpu_usages:
13
+ if usage < 10:
14
+ visual_line += "⬛️" # 非常に低い使用率(0-9%)
15
+ elif usage < 20:
16
+ visual_line += "🟦" # 低い使用率(10-19%)
17
+ elif usage < 30:
18
+ visual_line += "🟩" # やや低い使用率(20-29%)
19
+ elif usage < 50:
20
+ visual_line += "🟨" # 中程度の使用率(30-49%)
21
+ elif usage < 70:
22
+ visual_line += "🟧" # 高めの使用率(50-69%)
23
+ else:
24
+ visual_line += "🟥" # 非常に高い使用率(70-100%)
25
+ return visual_line
26
 
27
  def greet(name):
28
  start = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
29
  time.sleep(1)
30
+ print(get_cpu_usage_visual())
31
  end = datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%H:%M:%S")
32
  return f"[{name}] {start} ~ {end}"
33