Last active
December 17, 2018 22:35
-
-
Save frankgould/721636ece461ef8c510e449824c0e5dc to your computer and use it in GitHub Desktop.
using to determine wifi strength and display icon representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
temp = subprocess.Popen(args=['iwconfig wlan0 | grep -i quality'], stdout=subprocess.PIPE, shell=True) | |
wlan0_val, err = temp.communicate() | |
wlan0_strength = str(wlan0_val) | |
wlan0_strength = 'bb Link Quality=5/50 Signal level=-51 dBm \n' | |
cmp=wlan0_strength[25:33] | |
i=1 | |
while cmp[i]!='/': | |
i += 1 | |
cmp_num = cmp[:i] | |
i += 1 | |
j = i | |
while cmp[i]!=' ': | |
i += 1 | |
cmp_den = cmp[j:i] | |
try: | |
num = int(cmp_num) | |
den = int(cmp_den) | |
except: | |
num, den = 0 | |
if num > 10 and den > 10: | |
try: | |
wlan0_strength = num/den | |
except: | |
print('ERROR: set wifi indicator off') | |
if wlan0_strength < .2: | |
print(str(num) + '/' + str(den) + ' set wifi indicator low') | |
elif wlan0_strength < .5: | |
print(str(num) + '/' + str(den) + ' set wifi indicator half') | |
else: | |
print(str(num) + '/' + str(den) + ' set wifi indicator high') | |
else: | |
print(str(num) + '/' + str(den) + ' set wifi indicator off') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment