about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-10 23:27:09 +0200
committerManuel Palenzuela <manuelpalenzuelamerino@gmail.com>2019-06-10 23:27:09 +0200
commit44b24d4c370f24b324e57be8203fbb708919b4a7 (patch)
tree5f1e848bf5dbc40bbfd037a2827868063b5aae78
parentUpdated status bar (diff)
downloaddwm-44b24d4c370f24b324e57be8203fbb708919b4a7.tar.gz
dwm-44b24d4c370f24b324e57be8203fbb708919b4a7.tar.bz2
dwm-44b24d4c370f24b324e57be8203fbb708919b4a7.zip
Updated status bar
-rwxr-xr-xscripts/dwm-status15
-rw-r--r--scripts/weather.py40
2 files changed, 51 insertions, 4 deletions
diff --git a/scripts/dwm-status b/scripts/dwm-status
index 6996ae5..2569053 100755
--- a/scripts/dwm-status
+++ b/scripts/dwm-status
@@ -19,13 +19,20 @@ status() { \
 
 	# Get the volume of ALSA's master volume output.  Show an icon if or
 	# not muted.
-	amixer get Master | grep -o "[0-9]*%\|\[on\]\|\[off\]" | sed "s/\[on\]//;s/\[off\]//"
+	active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
+	curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
+	volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')
+	if [ "${curStatus}" = 'yes' ]
+	then
+			echo " $volume%"
+	else
+			echo " $volume%"
+	fi
 
 	echo "$delim"
 
-	# Wifi quality percentage and  icon if ethernet is connected.
+	# Wifi quality percentage
 	grep "^\s*w" /proc/net/wireless | awk '{ print "", int($3 * 100 / 70) "%" }'
-	sed "s/down//;s/up//" /sys/class/net/w*/operstate
 
 	# Show unread mail
 	command -v mw >/dev/null 2>&1 &&
@@ -63,5 +70,5 @@ while :; do
 	# Sleep for a minute after changing the status bar before updating it
 	# again. Note that the `refbar` "refreshes" the statusbar by killing
 	# this command. Feel free to change the time interval if you want.
-	sleep 1m
+	sleep 1s
 done
diff --git a/scripts/weather.py b/scripts/weather.py
new file mode 100644
index 0000000..ddf1ce7
--- /dev/null
+++ b/scripts/weather.py
@@ -0,0 +1,40 @@
+#!/bin/python
+
+import requests
+import os
+
+# Check for an internet connection
+url='http://www.google.com/'
+timeout=5
+try:
+    _ = requests.get(url, timeout=timeout)
+    internet = True
+except requests.ConnectionError:
+    internet = False
+
+COORDINATES = s = open("/usr/share/geolocate/.location", 'r').read()
+LOCATION = "lat=" + COORDINATES.replace(":","&lon=")
+
+API_KEY = "756edce7e9d4c385ef9499a53492678c"
+UNITS = "Metric"
+UNIT_KEY = "C"
+#UNIT_KEY = "F"
+LANG = "en"
+#LANG = "nl"
+#LANG = "hu"
+if internet == True:
+    API="http://api.openweathermap.org/data/2.5/weather?{}&lang={}&appid={}&units={}".format(LOCATION.strip(), LANG,  API_KEY, UNITS)
+    REQ = requests.get(API)
+    #REQ = requests.get("http://api.openweathermap.org/data/2.5/weather?lat=50.84660&lon=4.35280&lang=en&appid=756edce7e9d4c385ef9499a53492678c&units=Metric")
+    try:
+    # HTTP CODE = OK
+        if REQ.status_code == 200:
+            CURRENT = REQ.json()["weather"][0]["description"].capitalize()
+            TEMP = int(float(REQ.json()["main"]["temp"]))
+            print(" {}, {} °{}".format(CURRENT, TEMP, UNIT_KEY))
+        else:
+            print("Error: BAD HTTP STATUS CODE " + str(REQ.status_code))
+    except (ValueError, IOError):
+            print("Error: Unable print the data")
+else:
+    print("")