From 9fc8a3f06cfcd8bfd186948d3a0eb2118742db0e Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Fri, 24 Apr 2020 13:04:26 +0200 Subject: [PATCH] Change i3blocks scripts --- dotfiles/i3/blocks | 5 ----- dotfiles/i3/scripts/free_disk_space | 8 ++++++-- dotfiles/i3/scripts/protonvpn | 17 +++++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dotfiles/i3/blocks b/dotfiles/i3/blocks index 749cd0b..6876212 100644 --- a/dotfiles/i3/blocks +++ b/dotfiles/i3/blocks @@ -59,14 +59,9 @@ LABEL= DISK=/run/media/flyingscorpio/Backup [ccurrency] -LABEL=test command=scripts/ccurrency -f USD interval=1800 -[ccurrency] -command=scripts/ccurrency -f EUR -interval=1800 - [ccurrency] command=scripts/ccurrency -c ETH -f EUR interval=1800 diff --git a/dotfiles/i3/scripts/free_disk_space b/dotfiles/i3/scripts/free_disk_space index 2776e7c..b160c5a 100755 --- a/dotfiles/i3/scripts/free_disk_space +++ b/dotfiles/i3/scripts/free_disk_space @@ -12,9 +12,13 @@ def get_disk_free_space(disk: str) -> str: """Return available disk space in GiB.""" stat = os.statvfs(disk) - result = stat.f_bavail * stat.f_bsize / 1024 / 1024 / 1024 + total = stat.f_blocks * stat.f_bsize / 1024 / 1024 / 1024 + available = stat.f_bavail * stat.f_bsize / 1024 / 1024 / 1024 + percentage = (total - available) / total + avail_format = "{0:0.1f} GiB free".format(available) + percent_format = "({:.1%} used)".format(percentage) - return "{0:0.1f}".format(result) + " GiB free" + return "{} {}".format(avail_format, percent_format) OUTPUT = os.environ['LABEL'] + get_disk_free_space(os.environ["DISK"]) diff --git a/dotfiles/i3/scripts/protonvpn b/dotfiles/i3/scripts/protonvpn index 389b1f6..1a1ae0c 100755 --- a/dotfiles/i3/scripts/protonvpn +++ b/dotfiles/i3/scripts/protonvpn @@ -1,7 +1,12 @@ #!/usr/bin/python3 +"""Simple script for i3blocks for VPN status with ProtonVPN. + +Author: flyingscorpio +""" + import os -from protonvpn_cli import utils as pvpn_utils +from protonvpn_cli import utils as pvpn_utils # type: ignore IP_ADDR = pvpn_utils.get_ip_info()[0] @@ -11,11 +16,11 @@ if not pvpn_utils.is_connected(): OUTPUT += " {}".format(IP_ADDR) else: - CONNECTED_SERVER = pvpn_utils.get_config_value("metadata", "connected_server") - SERVERS = pvpn_utils.get_servers() - COUNTRY_CODE = pvpn_utils.get_server_value(CONNECTED_SERVER, "ExitCountry", SERVERS) - COUNTRY = pvpn_utils.get_country_name(COUNTRY_CODE) - CITY = pvpn_utils.get_server_value(CONNECTED_SERVER, "City", SERVERS) + SERVER = pvpn_utils.get_config_value("metadata", "connected_server") + ALL_SERVERS = pvpn_utils.get_servers() + CODE = pvpn_utils.get_server_value(SERVER, "ExitCountry", ALL_SERVERS) + COUNTRY = pvpn_utils.get_country_name(CODE) + CITY = pvpn_utils.get_server_value(SERVER, "City", ALL_SERVERS) OUTPUT = os.environ['LABEL_ON'] OUTPUT += " {} - {}, {}".format(IP_ADDR, CITY, COUNTRY)