Change i3blocks scripts

This commit is contained in:
flyingscorpio@arch-desktop 2020-04-24 13:04:26 +02:00
parent 8eb17bf11d
commit 9fc8a3f06c
3 changed files with 17 additions and 13 deletions

View file

@ -59,14 +59,9 @@ LABEL=<span foreground='#a1d569'>  </span>
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

View file

@ -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"])

View file

@ -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)