kunsis-dotfiles/.config/i3pystatus/rfkill-wifi.py

32 lines
702 B
Python
Raw Normal View History

2018-12-21 16:34:49 +00:00
#!/usr/bin/python
from subprocess import check_output
2018-12-21 16:34:49 +00:00
devices = {}
for line in check_output(['rfkill', '-rn']).decode('UTF-8').splitlines():
nr, identifier, device, soft, hard = line.split(' ')
devices[device] = {
'soft': True if soft == 'blocked' else False,
'hard': True if hard == 'blocked' else False,
}
2018-12-21 16:34:49 +00:00
2022-03-06 17:05:56 +00:00
wifi_dev = None
for device in devices:
if device.startswith('phy'):
wifi_dev = device
break
if not wifi_dev:
print('No WLAN?')
2018-12-21 16:34:49 +00:00
else:
2022-03-06 17:05:56 +00:00
if devices[wifi_dev]['hard']:
wlan = '#FF0000'
elif devices[wifi_dev]['soft']:
wlan = '#FF9900'
else:
wlan = '#00FF00'
2018-12-21 16:34:49 +00:00
2022-03-06 17:05:56 +00:00
print(f'<span color="{wlan}">WLAN</span>')