LoginSignup
26
32

Pythonでバッテリ残量とメモリ残量を出力してみた

Last updated at Posted at 2024-03-10

普段PCを落とさないためメモリやバッテリ残量が気になったので作成してLINEに飛ばすようにした

バッテリー残量

Python

def batterry():#バッテリ残量を表示
    import psutil
    dsk = psutil.disk_usage('/')
    btr = psutil.sensors_battery()
    btr = f"{btr.percent}%"
    print(btr)
    return btr

メモリ残量

Python
def disk_usage():  # ディスク使用状況を表示
    import psutil
    path = '/'
    disk_info = psutil.disk_usage(path)
    total = disk_info.total / (1024 ** 3)  # ギガバイト単位に変換
    used = disk_info.used / (1024 ** 3)
    free = disk_info.free / (1024 ** 3)
    total = "{:.2f}".format(total)
    used = "{:.2f}".format(used)
    free = "{:.2f}".format(free)
    print(disk_info)
    print(f"合計容量{total}GB")
    print(f"使用容量{used}GB")
    print(f"空き容量{free}GB")

    return total, used, free

これで安心

26
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
32