Add files via upload

This commit is contained in:
Quinta
2023-03-18 22:21:53 +01:00
committed by GitHub
commit fd733cd338
100 changed files with 8809 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
#!/bin/sh
# If ACPI was not installed, this probably is a battery-less computer.
ACPI_RES=$(acpi -b)
ACPI_CODE=$?
if [ $ACPI_CODE -eq 0 ]
then
# Get essential information. Due to som bug with some versions of acpi it is
# worth filtering the ACPI result from all lines containing "unavailable".
BAT_LEVEL_ALL=$(echo "$ACPI_RES" | grep -v "unavailable" | grep -E -o "[0-9][0-9]?[0-9]?%")
BAT_LEVEL=$(echo "$BAT_LEVEL_ALL" | awk -F"%" 'BEGIN{tot=0;i=0} {i++; tot+=$1} END{printf("%d%%\n", tot/i)}')
TIME_LEFT=$(echo "$ACPI_RES" | grep -v "unavailable" | grep -E -o "[0-9]{2}:[0-9]{2}:[0-9]{2}")
IS_CHARGING=$(echo "$ACPI_RES" | grep -v "unavailable" | awk '{ printf("%s\n", substr($3, 0, length($3)-1) ) }')
# If there is no 'time left' information (when almost fully charged) we
# provide information ourselvs.
if [ -z "$TIME_LEFT" ]
then
TIME_LEFT="00:00:00"
fi
# Print full text. The charging data.
TIME_LEFT=$(echo $TIME_LEFT | awk '{ printf("%s\n", substr($1, 0, 5)) }')
echo "🔋$BAT_LEVEL ⏳$TIME_LEFT "
# Print the short text.
echo "BAT: $BAT_LEVEL"
# Change the font color, depending on the situation.
if [ "$IS_CHARGING" = "Charging" ]
then
# Charging yellow color.
echo "#D0D000"
else
if [ "${BAT_LEVEL%?}" -le 15 ]
then
# Battery very low. Red color.
echo "#FA1E44"
else
# Battery not charging but at decent level. Green color.
echo "#007872"
fi
fi
fi
+43
View File
@@ -0,0 +1,43 @@
[WEATHER_SIGNALER]
command=~/.config/i3blocks/weather/weather_signaler
interval=once
[WEATHER]
command=~/.config/i3blocks/weather/weather_info.sh
interval=300
color=#FEC925
signal=2
[DISK]
command=df -h / | awk '/\//{ printf(" 💾 %4s/%s \n", $4, $2) }'
interval=2
color=#C9E3DB
[BATTERY]
command=~/.config/i3blocks/battery/battery_info.sh
interval=3
[CPU]
full_text= CPU: 0.00% @ +00.0°C
command=~/.config/i3blocks/cpu/cpu_info.sh
interval=repeat
color=#00B4EB
[MEM]
command=free -h | awk '/Mem:/ { printf(" 🐏 %5s/%s \n", $3, $2) }'
interval=1
color=#FEC925
[SOUND_BURST]
command=~/.config/i3blocks/sound/sound_burst.sh
interval=once
[SOUND]
full_text= 🔇: 0%
command=~/.config/i3blocks/sound/sound_info.sh
interval=0
signal=1
[TIME_DATE]
command=date +" %a, %d %b - %H:%M:%S"
interval=1
+4
View File
@@ -0,0 +1,4 @@
#!/bin/sh
TEMP=$(sensors | grep 'Package id 0:\|Tdie' | grep ':[ ]*+[0-9]*.[0-9]*°C' -o | grep '+[0-9]*.[0-9]*°C' -o)
CPU_USAGE=$(mpstat 1 1 | awk '/Average:/ {printf("%s\n", $(NF-9))}')
echo "$CPU_USAGE $TEMP" | awk '{ printf(" CPU:%6s% @ %s \n"), $1, $2 }'
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
for i in $(seq 1 10)
do
sleep 0.2
pkill -RTMIN+1 i3blocks
done
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
VOLUME_MUTE="🔇"
VOLUME_LOW="🔈"
VOLUME_MID="🔉"
VOLUME_HIGH="🔊"
SOUND_LEVEL=$(amixer -M get Master | awk -F"[][]" '/%/ { print $2 }' | awk -F"%" 'BEGIN{tot=0; i=0} {i++; tot+=$1} END{printf("%s\n", tot/i) }')
MUTED=$(amixer get Master | awk ' /%/{print ($NF=="[off]" ? 1 : 0); exit;}')
ICON=$VOLUME_MUTE
if [ "$MUTED" = "1" ]
then
ICON="$VOLUME_MUTE"
else
if [ "$SOUND_LEVEL" -lt 34 ]
then
ICON="$VOLUME_LOW"
elif [ "$SOUND_LEVEL" -lt 67 ]
then
ICON="$VOLUME_MID"
else
ICON="$VOLUME_HIGH"
fi
fi
echo "$ICON" "$SOUND_LEVEL" | awk '{ printf(" %s:%3s%% \n", $1, $2) }'
+11
View File
@@ -0,0 +1,11 @@
CC = gcc
CFLAGS = -O2 -Wall -Wextra -Wpedantic
LINKFLAGS = -lrt
.PHONY: clean
weather_signaler: weather_signaler.c
$(CC) $(CFLAGS) $< -o weather_signaler $(LINKFLAGS)
clean:
@rm -v weather_signaler
+417
View File
@@ -0,0 +1,417 @@
<?xml version="1.0" encoding="utf-8"?>
<weatherdata>
<apiChanges>
<!--NB!!! Since we have no other options to contact our users of forecast.xml, we have decided to use this method to get your attention to some major changes with our API-->
<!--This summer, forecast.xml and forecast_hour_by_hour.xml will be discontinued in favour of a newer JSON API. An exactly date is not set yet.-->
<!--Vi encourage you already now to switch to the new API.-->
<!--There are a lot of changes, and you can read all the technical details in our new developer portal https://developer.yr.no-->
</apiChanges>
<location>
<name>Linköping</name>
<type>Regional capital</type>
<country>Sweden</country>
<timezone id="Europe/Stockholm" utcoffsetMinutes="60" />
<location altitude="58" latitude="58.41086" longitude="15.62157" geobase="geonames" geobaseid="2694762" />
</location>
<credit>
<!--In order to use the free weather data from yr no, you HAVE to display
the following text clearly visible on your web page. The text should be a
link to the specified URL.-->
<!--Please read more about our conditions and guidelines at http://om.yr.no/verdata/ English explanation at http://om.yr.no/verdata/free-weather-data/-->
<link text="Weather forecast from Yr, delivered by the Norwegian Meteorological Institute and the NRK" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/" />
</credit>
<links>
<link id="xmlSource" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/forecast.xml" />
<link id="xmlSourceHourByHour" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/forecast_hour_by_hour.xml" />
<link id="overview" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/" />
<link id="hourByHour" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/hour_by_hour" />
<link id="longTermForecast" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/long" />
<link id="nowcast" url="http://www.yr.no/place/Sweden/Östergötland/Linköping/varsel_nu.xml" />
</links>
<meta>
<lastupdate>2022-01-07T17:14:00</lastupdate>
<nextupdate>2022-01-07T18:14:00</nextupdate>
</meta>
<sun rise="2022-01-07T08:42:34" set="2022-01-07T15:25:27" />
<forecast>
<tabular>
<time from="2022-01-07T17:00:00" to="2022-01-07T18:00:00" period="2">
<!-- Valid from 2022-01-07T17:00:00 to 2022-01-07T18:00:00 -->
<symbol number="13" numberEx="13" name="Snow" var="13" />
<precipitation value="0.3" minvalue="0.2" maxvalue="0.6" />
<!-- Valid at 2022-01-07T17:00:00 -->
<windDirection deg="132.7" code="SE" name="Southeast" />
<windSpeed mps="3.0" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1005.3" />
</time>
<time from="2022-01-07T18:00:00" to="2022-01-08T00:00:00" period="3">
<!-- Valid from 2022-01-07T18:00:00 to 2022-01-08T00:00:00 -->
<symbol number="13" numberEx="13" name="Snow" var="13" />
<precipitation value="3.5" minvalue="1.2" maxvalue="4.3" />
<!-- Valid at 2022-01-07T18:00:00 -->
<windDirection deg="130.9" code="SE" name="Southeast" />
<windSpeed mps="2.7" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1005.1" />
</time>
<time from="2022-01-08T00:00:00" to="2022-01-08T06:00:00" period="0">
<!-- Valid from 2022-01-08T00:00:00 to 2022-01-08T06:00:00 -->
<symbol number="13" numberEx="13" name="Snow" var="13" />
<precipitation value="1.3" minvalue="0" maxvalue="3.0" />
<!-- Valid at 2022-01-08T00:00:00 -->
<windDirection deg="148.3" code="SSE" name="South-southeast" />
<windSpeed mps="2.2" name="Light breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1004.3" />
</time>
<time from="2022-01-08T06:00:00" to="2022-01-08T12:00:00" period="1">
<!-- Valid from 2022-01-08T06:00:00 to 2022-01-08T12:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" minvalue="0" maxvalue="0.8" />
<!-- Valid at 2022-01-08T06:00:00 -->
<windDirection deg="198.4" code="SSW" name="South-southwest" />
<windSpeed mps="1.7" name="Light breeze" />
<temperature unit="celsius" value="-2" />
<pressure unit="hPa" value="1002.8" />
</time>
<time from="2022-01-08T12:00:00" to="2022-01-08T18:00:00" period="2">
<!-- Valid from 2022-01-08T12:00:00 to 2022-01-08T18:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d" />
<precipitation value="0" minvalue="0" maxvalue="0.8" />
<!-- Valid at 2022-01-08T12:00:00 -->
<windDirection deg="186.1" code="S" name="South" />
<windSpeed mps="1.8" name="Light breeze" />
<temperature unit="celsius" value="1" />
<pressure unit="hPa" value="1001.6" />
</time>
<time from="2022-01-08T18:00:00" to="2022-01-09T00:00:00" period="3">
<!-- Valid from 2022-01-08T18:00:00 to 2022-01-09T00:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" minvalue="0" maxvalue="1.2" />
<!-- Valid at 2022-01-08T18:00:00 -->
<windDirection deg="134.3" code="SE" name="Southeast" />
<windSpeed mps="1.8" name="Light breeze" />
<temperature unit="celsius" value="-3" />
<pressure unit="hPa" value="999.3" />
</time>
<time from="2022-01-09T00:00:00" to="2022-01-09T06:00:00" period="0">
<!-- Valid from 2022-01-09T00:00:00 to 2022-01-09T06:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-09T00:00:00 -->
<windDirection deg="52.4" code="NE" name="Northeast" />
<windSpeed mps="2.1" name="Light breeze" />
<temperature unit="celsius" value="-2" />
<pressure unit="hPa" value="998.2" />
</time>
<time from="2022-01-09T06:00:00" to="2022-01-09T12:00:00" period="1">
<!-- Valid from 2022-01-09T06:00:00 to 2022-01-09T12:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-09T06:00:00 -->
<windDirection deg="55.3" code="NE" name="Northeast" />
<windSpeed mps="3.0" name="Light breeze" />
<temperature unit="celsius" value="-2" />
<pressure unit="hPa" value="999.5" />
</time>
<time from="2022-01-09T12:00:00" to="2022-01-09T18:00:00" period="2">
<!-- Valid from 2022-01-09T12:00:00 to 2022-01-09T18:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-09T12:00:00 -->
<windDirection deg="44.7" code="NE" name="Northeast" />
<windSpeed mps="2.6" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1003.6" />
</time>
<time from="2022-01-09T18:00:00" to="2022-01-10T00:00:00" period="3">
<!-- Valid from 2022-01-09T18:00:00 to 2022-01-10T00:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" minvalue="0" maxvalue="0.9" />
<!-- Valid at 2022-01-09T18:00:00 -->
<windDirection deg="53.3" code="NE" name="Northeast" />
<windSpeed mps="2.1" name="Light breeze" />
<temperature unit="celsius" value="-2" />
<pressure unit="hPa" value="1008.8" />
</time>
<time from="2022-01-10T01:00:00" to="2022-01-10T07:00:00" period="0">
<!-- Valid from 2022-01-10T01:00:00 to 2022-01-10T07:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-10T01:00:00 -->
<windDirection deg="53.0" code="NE" name="Northeast" />
<windSpeed mps="2.0" name="Light breeze" />
<temperature unit="celsius" value="-3" />
<pressure unit="hPa" value="1016.7" />
</time>
<time from="2022-01-10T07:00:00" to="2022-01-10T13:00:00" period="1">
<!-- Valid from 2022-01-10T07:00:00 to 2022-01-10T13:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-10T07:00:00 -->
<windDirection deg="61.4" code="ENE" name="East-northeast" />
<windSpeed mps="2.0" name="Light breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1021.3" />
</time>
<time from="2022-01-10T13:00:00" to="2022-01-10T19:00:00" period="2">
<!-- Valid from 2022-01-10T13:00:00 to 2022-01-10T19:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-10T13:00:00 -->
<windDirection deg="77.3" code="ENE" name="East-northeast" />
<windSpeed mps="2.1" name="Light breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1027.0" />
</time>
<time from="2022-01-10T19:00:00" to="2022-01-11T01:00:00" period="3">
<!-- Valid from 2022-01-10T19:00:00 to 2022-01-11T01:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-10T19:00:00 -->
<windDirection deg="87.6" code="E" name="East" />
<windSpeed mps="2.0" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1030.7" />
</time>
<time from="2022-01-11T01:00:00" to="2022-01-11T07:00:00" period="0">
<!-- Valid from 2022-01-11T01:00:00 to 2022-01-11T07:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-11T01:00:00 -->
<windDirection deg="169.9" code="S" name="South" />
<windSpeed mps="1.7" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1031.8" />
</time>
<time from="2022-01-11T07:00:00" to="2022-01-11T13:00:00" period="1">
<!-- Valid from 2022-01-11T07:00:00 to 2022-01-11T13:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-11T07:00:00 -->
<windDirection deg="179.0" code="S" name="South" />
<windSpeed mps="3.0" name="Light breeze" />
<temperature unit="celsius" value="-1" />
<pressure unit="hPa" value="1031.4" />
</time>
<time from="2022-01-11T13:00:00" to="2022-01-11T19:00:00" period="2">
<!-- Valid from 2022-01-11T13:00:00 to 2022-01-11T19:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-11T13:00:00 -->
<windDirection deg="195.1" code="SSW" name="South-southwest" />
<windSpeed mps="3.7" name="Gentle breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1031.0" />
</time>
<time from="2022-01-11T19:00:00" to="2022-01-12T01:00:00" period="3">
<!-- Valid from 2022-01-11T19:00:00 to 2022-01-12T01:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-11T19:00:00 -->
<windDirection deg="201.9" code="SSW" name="South-southwest" />
<windSpeed mps="3.7" name="Gentle breeze" />
<temperature unit="celsius" value="1" />
<pressure unit="hPa" value="1029.4" />
</time>
<time from="2022-01-12T01:00:00" to="2022-01-12T07:00:00" period="0">
<!-- Valid from 2022-01-12T01:00:00 to 2022-01-12T07:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-12T01:00:00 -->
<windDirection deg="206.6" code="SSW" name="South-southwest" />
<windSpeed mps="3.0" name="Light breeze" />
<temperature unit="celsius" value="2" />
<pressure unit="hPa" value="1027.9" />
</time>
<time from="2022-01-12T07:00:00" to="2022-01-12T13:00:00" period="1">
<!-- Valid from 2022-01-12T07:00:00 to 2022-01-12T13:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-12T07:00:00 -->
<windDirection deg="224.9" code="SW" name="Southwest" />
<windSpeed mps="4.2" name="Gentle breeze" />
<temperature unit="celsius" value="2" />
<pressure unit="hPa" value="1024.4" />
</time>
<time from="2022-01-12T13:00:00" to="2022-01-12T19:00:00" period="2">
<!-- Valid from 2022-01-12T13:00:00 to 2022-01-12T19:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-12T13:00:00 -->
<windDirection deg="235.5" code="SW" name="Southwest" />
<windSpeed mps="6.4" name="Moderate breeze" />
<temperature unit="celsius" value="4" />
<pressure unit="hPa" value="1019.8" />
</time>
<time from="2022-01-12T19:00:00" to="2022-01-13T01:00:00" period="3">
<!-- Valid from 2022-01-12T19:00:00 to 2022-01-13T01:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n" />
<precipitation value="0" />
<!-- Valid at 2022-01-12T19:00:00 -->
<windDirection deg="238.5" code="WSW" name="West-southwest" />
<windSpeed mps="7.3" name="Moderate breeze" />
<temperature unit="celsius" value="5" />
<pressure unit="hPa" value="1013.4" />
</time>
<time from="2022-01-13T01:00:00" to="2022-01-13T07:00:00" period="0">
<!-- Valid from 2022-01-13T01:00:00 to 2022-01-13T07:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n" />
<precipitation value="0" />
<!-- Valid at 2022-01-13T01:00:00 -->
<windDirection deg="256.1" code="WSW" name="West-southwest" />
<windSpeed mps="7.0" name="Moderate breeze" />
<temperature unit="celsius" value="6" />
<pressure unit="hPa" value="1012.5" />
</time>
<time from="2022-01-13T07:00:00" to="2022-01-13T13:00:00" period="1">
<!-- Valid from 2022-01-13T07:00:00 to 2022-01-13T13:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d" />
<precipitation value="0" />
<!-- Valid at 2022-01-13T07:00:00 -->
<windDirection deg="257.2" code="WSW" name="West-southwest" />
<windSpeed mps="7.5" name="Moderate breeze" />
<temperature unit="celsius" value="6" />
<pressure unit="hPa" value="1010.1" />
</time>
<time from="2022-01-13T13:00:00" to="2022-01-13T19:00:00" period="2">
<!-- Valid from 2022-01-13T13:00:00 to 2022-01-13T19:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d" />
<precipitation value="0" />
<!-- Valid at 2022-01-13T13:00:00 -->
<windDirection deg="258.2" code="WSW" name="West-southwest" />
<windSpeed mps="7.8" name="Moderate breeze" />
<temperature unit="celsius" value="8" />
<pressure unit="hPa" value="1006.4" />
</time>
<time from="2022-01-13T19:00:00" to="2022-01-14T01:00:00" period="3">
<!-- Valid from 2022-01-13T19:00:00 to 2022-01-14T01:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n" />
<precipitation value="0" />
<!-- Valid at 2022-01-13T19:00:00 -->
<windDirection deg="272.2" code="W" name="West" />
<windSpeed mps="8.7" name="Fresh breeze" />
<temperature unit="celsius" value="8" />
<pressure unit="hPa" value="1003.6" />
</time>
<time from="2022-01-14T01:00:00" to="2022-01-14T07:00:00" period="0">
<!-- Valid from 2022-01-14T01:00:00 to 2022-01-14T07:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n" />
<precipitation value="0" />
<!-- Valid at 2022-01-14T01:00:00 -->
<windDirection deg="273.9" code="W" name="West" />
<windSpeed mps="8.8" name="Fresh breeze" />
<temperature unit="celsius" value="8" />
<pressure unit="hPa" value="1000.4" />
</time>
<time from="2022-01-14T07:00:00" to="2022-01-14T13:00:00" period="1">
<!-- Valid from 2022-01-14T07:00:00 to 2022-01-14T13:00:00 -->
<symbol number="1" numberEx="1" name="Clear sky" var="01d" />
<precipitation value="0" />
<!-- Valid at 2022-01-14T07:00:00 -->
<windDirection deg="273.8" code="W" name="West" />
<windSpeed mps="7.4" name="Moderate breeze" />
<temperature unit="celsius" value="5" />
<pressure unit="hPa" value="998.6" />
</time>
<time from="2022-01-14T13:00:00" to="2022-01-14T19:00:00" period="2">
<!-- Valid from 2022-01-14T13:00:00 to 2022-01-14T19:00:00 -->
<symbol number="1" numberEx="1" name="Clear sky" var="01d" />
<precipitation value="0" />
<!-- Valid at 2022-01-14T13:00:00 -->
<windDirection deg="293.1" code="WNW" name="West-northwest" />
<windSpeed mps="7.3" name="Moderate breeze" />
<temperature unit="celsius" value="5" />
<pressure unit="hPa" value="1001.1" />
</time>
<time from="2022-01-14T19:00:00" to="2022-01-15T01:00:00" period="3">
<!-- Valid from 2022-01-14T19:00:00 to 2022-01-15T01:00:00 -->
<symbol number="1" numberEx="1" name="Clear sky" var="01n" />
<precipitation value="0" />
<!-- Valid at 2022-01-14T19:00:00 -->
<windDirection deg="265.1" code="W" name="West" />
<windSpeed mps="7.2" name="Moderate breeze" />
<temperature unit="celsius" value="3" />
<pressure unit="hPa" value="1002.1" />
</time>
<time from="2022-01-15T01:00:00" to="2022-01-15T07:00:00" period="0">
<!-- Valid from 2022-01-15T01:00:00 to 2022-01-15T07:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03n" />
<precipitation value="0" />
<!-- Valid at 2022-01-15T01:00:00 -->
<windDirection deg="304.0" code="NW" name="Northwest" />
<windSpeed mps="6.9" name="Moderate breeze" />
<temperature unit="celsius" value="2" />
<pressure unit="hPa" value="1004.6" />
</time>
<time from="2022-01-15T07:00:00" to="2022-01-15T13:00:00" period="1">
<!-- Valid from 2022-01-15T07:00:00 to 2022-01-15T13:00:00 -->
<symbol number="1" numberEx="1" name="Clear sky" var="01d" />
<precipitation value="0" />
<!-- Valid at 2022-01-15T07:00:00 -->
<windDirection deg="303.9" code="NW" name="Northwest" />
<windSpeed mps="5.5" name="Moderate breeze" />
<temperature unit="celsius" value="1" />
<pressure unit="hPa" value="1005.8" />
</time>
<time from="2022-01-15T13:00:00" to="2022-01-15T19:00:00" period="2">
<!-- Valid from 2022-01-15T13:00:00 to 2022-01-15T19:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d" />
<precipitation value="0" />
<!-- Valid at 2022-01-15T13:00:00 -->
<windDirection deg="325.6" code="NW" name="Northwest" />
<windSpeed mps="5.9" name="Moderate breeze" />
<temperature unit="celsius" value="2" />
<pressure unit="hPa" value="1007.7" />
</time>
<time from="2022-01-15T19:00:00" to="2022-01-16T01:00:00" period="3">
<!-- Valid from 2022-01-15T19:00:00 to 2022-01-16T01:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-15T19:00:00 -->
<windDirection deg="313.4" code="NW" name="Northwest" />
<windSpeed mps="5.1" name="Gentle breeze" />
<temperature unit="celsius" value="1" />
<pressure unit="hPa" value="1009.1" />
</time>
<time from="2022-01-16T01:00:00" to="2022-01-16T07:00:00" period="0">
<!-- Valid from 2022-01-16T01:00:00 to 2022-01-16T07:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-16T01:00:00 -->
<windDirection deg="268.7" code="W" name="West" />
<windSpeed mps="2.5" name="Light breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1010.9" />
</time>
<time from="2022-01-16T07:00:00" to="2022-01-16T13:00:00" period="1">
<!-- Valid from 2022-01-16T07:00:00 to 2022-01-16T13:00:00 -->
<symbol number="4" numberEx="4" name="Cloudy" var="04" />
<precipitation value="0" />
<!-- Valid at 2022-01-16T07:00:00 -->
<windDirection deg="24.7" code="NNE" name="North-northeast" />
<windSpeed mps="3.3" name="Light breeze" />
<temperature unit="celsius" value="0" />
<pressure unit="hPa" value="1005.4" />
</time>
<time from="2022-01-16T13:00:00" to="2022-01-16T19:00:00" period="2">
<!-- Valid from 2022-01-16T13:00:00 to 2022-01-16T19:00:00 -->
<symbol number="3" numberEx="3" name="Partly cloudy" var="03d" />
<precipitation value="0" />
<!-- Valid at 2022-01-16T13:00:00 -->
<windDirection deg="307.1" code="NW" name="Northwest" />
<windSpeed mps="3.7" name="Gentle breeze" />
<temperature unit="celsius" value="1" />
<pressure unit="hPa" value="1011.4" />
</time>
</tabular>
</forecast>
<weatherstation stno="0" sttype="" name="" distance="0" lat="0" lon="0" source="">
<!--Observasjoner er ikke lengre tilgjengelig i dette datasettet. Observations are no longer availble in this dataset-->
<symbol number="0" name="" time="2019-11-14T00:00:00Z" />
<temperature unit="" value="0" time="2019-11-14T00:00:00Z" />
<windDirection deg="0" code="" name="" time="2019-11-14T00:00:00Z" />
<windSpeed mps="0" name="" time="2019-11-14T00:00:00Z" />
</weatherstation>
</weatherdata>
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/python3
''' Weather acquirer for: https://github.com/miklhh/i3blocks-config '''
import os
import datetime
import xml.etree.ElementTree as ET
import requests
# Forecast URL.
YR_URL = "https://www.yr.no/place/Sverige/%C3%96sterg%C3%B6tland/Link%C3%B6ping/forecast.xml"
# Good to have data + funky emojicons.
FORECAST_CACHE_FILE = os.path.dirname(os.path.realpath(__file__)) + "/forecast.xml"
# Emojis associatted with weather # Day # Night
WEATHER_TYPES = { "Fair" : ["☀️", "🌙"], #pylint: disable=C0326
"Partly cloudy" : ["⛅", "☁️"], #pylint: disable=C0326
"Clear sky" : ["☀️", "🌙"], #pylint: disable=C0326
"Cloudy" : ["☁️", "☁️"], #pylint: disable=C0326
"Light rain" : ["🌧️", "🌧️"], #pylint: disable=C0326
"Rain" : ["🌧️", "🌧️"], #pylint: disable=C0326
"Heavy Rain" : ["🌧️", "🌧️"], #pylint: disable=C0326
"Light snow" : ["🌨️", "🌨️"], #pylint: disable=C0326
"Snow" : ["🌨️", "🌨️"], #pylint: disable=C0326
"Heavy snow" : ["🌨️", "🌨️"], #pylint: disable=C0326
"Foggy" : ["🌫️", "🌫️"], #pylint: disable=C0326
"Fog" : ["🌫️", "🌫️"], #pylint: disable=C0326
"Light snow showers" : ["🌨️", "🌨️"]} #pylint: disable=C0326
def get_xml_root():
""" Returns a weather XML root, cached from old data if necessary. """
yr_response = 0
try:
# Request data from YR.
yr_response = requests.get(YR_URL)
if yr_response.status_code != 200:
raise RuntimeError('Error: YR status code ' + str(yr_response.status_code))
# New response, store in cache file and return XML root.
with open(FORECAST_CACHE_FILE, "w") as file_handle:
file_handle.write(yr_response.text)
return ET.fromstring(yr_response.text)
except requests.ConnectionError:
# Probably just no internet. Use cached forecast.
if os.path.isfile(FORECAST_CACHE_FILE):
with open(FORECAST_CACHE_FILE) as file_handle:
yr_response = file_handle.read()
# Print recycle emoji and continue using cached forecast.
print("(♻️)", end=" ")
return ET.fromstring(yr_response)
# Dead end, no XML-root acquired.
raise RuntimeError('No forecast data available.')
def main():
""" Entry point for program. """
# Get the XML root.
try:
xml_root = get_xml_root()
except RuntimeError as exception:
print(exception)
# Parse the sun rise and set time. Appearntly, they are not always available and
# so we need to make sure they exist in the recieved data.
rise_fall_available = True
sun_rise_time = sun_set_time = ""
try:
sun_rise_time = xml_root.find("sun").attrib.get("rise")
sun_rise_time = sun_rise_time[sun_rise_time.find('T')+1 : len(sun_rise_time)-3]
sun_set_time = xml_root.find("sun").attrib.get("set")
sun_set_time = sun_set_time[sun_set_time.find('T')+1 : len(sun_set_time)-3]
except (ET.ParseError, AttributeError):
rise_fall_available = False
# Get the current weather information.
forecast = xml_root.find("forecast").find("tabular").find("time")
weather = forecast.find("symbol").attrib.get("name")
temperature = forecast.find("temperature").attrib.get("value")
wind_direction = forecast.find("windDirection").attrib.get("code")
wind_speed = forecast.find("windSpeed").attrib.get("mps")
precipitation = forecast.find("precipitation").attrib.get("value")
# Night time?
is_night = 0
now = datetime.datetime.now()
if rise_fall_available:
# Use sun rise and fall time to determine.
sun_rise = datetime.datetime.strptime(sun_rise_time, "%H:%M")
sun_set = datetime.datetime.strptime(sun_set_time, "%H:%M")
is_night = 1 if now.time() < sun_rise.time() or sun_set.time() < now.time() else 0
else:
# No rise/fall time available. Approximate daytime as [07:00 - 21:00].
sun_rise = datetime.datetime.strptime("07:00", "%H:%M")
sun_set = datetime.datetime.strptime("21:00", "%H:%M")
is_night = 1 if now.time() < sun_rise.time() or sun_set.time() < now.time() else 0
# Print the weather.
if weather in WEATHER_TYPES:
# Emoji is avaiable for usage.
print(weather + ": " + WEATHER_TYPES.get(weather)[is_night] + " ", end="")
else:
# No emoji available, use regular text.
print(weather + " ", end="")
# Print the temperature and sun times.
print(temperature, end="°C ")
# Print the sun rise and set time.
if rise_fall_available:
print("[" + sun_rise_time + " 🌅 " + sun_set_time + "]", end=" ")
# Print the precipitation (if there is any).
if precipitation != "0":
# Print with a wet umbrella
print("| ☔ " + precipitation + "mm", end=" ")
# Print wind data.
print("| 🍃 " + wind_speed + "m/s " + "(" + wind_direction + ")", end="")
# Go gadget, go!
main()
+2
View File
@@ -0,0 +1,2 @@
#!/bin/sh
echo " $(~/.config/i3blocks/weather/weather.py) "
Binary file not shown.
+102
View File
@@ -0,0 +1,102 @@
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <time.h>
#include <stdio.h>
// Sleep time between daemon updates.
#define SLEEP_TIME_S 300
// Test for internet connection. Returns true if connection is established.
static int test_internet_connection()
{
const char *cmd = "nc -zw1 google.com 443 1> /dev/null 2>&1";
return !system(cmd);
}
// Signal handler for signaling the weather applet.
static void timer_handler(int sig, siginfo_t *si, void *uc)
{
(void) sig; // Ignore parameter.
(void) si; // Ignore parameter.
(void) uc; // Ignore parameter.
// Test for internet connection till found or 20 times.
for (int i = 0; i < 20; ++i)
{
if (test_internet_connection())
{
// Connection established. Break out.
break;
}
else
{
// Retry every second.
sleep(1);
}
}
// Signal the weather applet.
const char *cmd = "pkill -RTMIN+2 i3blocks";
if ( system(cmd) )
{
// Error message should be printed to stdout since stdout is the way to
// interface with a user in i3blocks.
puts("WEATHER_SIGNALER ERROR\n");
}
}
int timer_init_launch(
timer_t *timer,
struct sigevent *sev,
struct sigaction *sa,
struct itimerspec *tspec)
{
// Event initialization.
sev->sigev_notify = SIGEV_SIGNAL;
sev->sigev_signo = SIGRTMIN;
sev->sigev_value.sival_ptr = timer;
// Signal action type initializaion.
sa->sa_flags = SA_SIGINFO;
sa->sa_sigaction = timer_handler;
sigemptyset(&sa->sa_mask);
if (sigaction(SIGRTMIN, sa, NULL) == -1)
return -1;
// Initialze timer.
if (timer_create(CLOCK_BOOTTIME, sev, timer) == -1)
return -1;
// Start the timer.
tspec->it_value.tv_sec = SLEEP_TIME_S;
tspec->it_value.tv_nsec = 0;
tspec->it_interval.tv_sec = SLEEP_TIME_S;
tspec->it_interval.tv_nsec = 0;
if (timer_settime(*timer, 0, tspec, NULL) == -1)
return -1;
// Initialization successful.
return 0;
}
int main()
{
timer_t timer;
struct sigevent sev;
struct sigaction sa;
struct itimerspec tspec;
// Initialize signaler
if (timer_init_launch(&timer, &sev, &sa, &tspec))
exit(EXIT_FAILURE);
// Signal on daemon launch.
sleep(1);
timer_handler(0, NULL, NULL);
while(1)
{
sleep(100);
}
}