Last active
April 2, 2018 18:12
-
-
Save rewida17/a487eb038847dd50c338c1a038beb424 to your computer and use it in GitHub Desktop.
Shell based AIRly user iface
This file contains hidden or 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
#!/bin/bash | |
APIK="apikey:Your Airly API KEY" | |
########################################################################### | |
# | |
json2txt(){ | |
sed 's/\\\\\//\//g' |\ | |
sed 's/[{}]//g' |\ | |
awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}'|\ | |
sed 's/[\,]/ /g' |\ | |
sed 's/\"//g' | |
} | |
############################################################################ | |
#Tłumacz na Polski | |
POLI(){ | |
sed 's/currentMeasurements:airQualityIndex:/CQI =>,/g; s/pressure:/Ciśnienie => ,/; s/humidity:/Wilgotność =>,/; s/pm1:/Pył PM-1 =>,/; s/pm25:/Pył PM-2.5 =>,/; s/pm10:/Pył PM-10 => ,/; s/^temperature:/Temp[°C] =>,/; s/pollutionLevel:/Skala_Zaniecz =>,/;' | |
} | |
############################################################################ | |
#Zaokrąglanie wyników | |
RoundUP(){ | |
awk -F ">" 'BEGIN {print "Pomiar"}; /.*/ {printf $1 "%3.0f", $2}' | |
} | |
############################################################################ | |
curl -s -X GET --header 'Accept: application/json' --header "$APIK" "https://airapi.airly.eu/v1/sensor/measurements?sensorId=NUMER_ID_SENSORA" |json2txt| \ | |
sed -n '1,8p'| POLI |awk -F"," 'BEGIN {print "Pomiar GDZIEŚ_TAM ;)"}; /.*/ {printf $1 "%3.0f\n", $2}' | |
curl -s -X GET --header 'Accept: application/json' --header "$APIK" "https://airapi.airly.eu/v1/sensor/measurements?sensorId=919" |json2txt| \ | |
sed -n '1,8p'| POLI |awk -F"," 'BEGIN {print "Pomiar Sosnowa"}; /.*/ {printf $1 "%3.0f\n", $2}'> /tmp/airly | |
# | |
if [ "$CQI" -ge 1 ] && [ "$CQI" -le 22 ] | |
then | |
echo -e "\\nCQI=$CQI\\nWspaniałe powietrze!\\nIdealny dzień na aktywność na świeżym powietrzu :3\\n" >> /tmp/airly | |
elif [ "$CQI" -gt 22 ] && [ "$CQI" -le 25 ] | |
then | |
echo -e "\\nCQI=$CQI\\nDobre powietrze.\\nMożesz bez obaw wyjść na zewnątrz i cieszyć się dniem :D\\n" >> /tmp/airly | |
elif [ "$CQI" -gt 25 ] && [ "$CQI" -le 40 ] | |
then | |
echo -e "\\nCQI=$CQI\\nŚrednie Powietrze\\nJeśli nie musisz wychodzić, lepiej zostań w domu\\n" >> /tmp/airly | |
elif [ "$CQI" -gt 40 ] && [ "$CQI" -le 50 ] | |
then | |
echo -e "\\nCQI=$CQI\\nZła jakość powietrza, Zostań w domu\\n" >> /tmp/airly | |
elif [ "$CQI" -gt 50 ] && [ "$CQI" -le 200 ] | |
then | |
echo -e "\\nCQI=$CQI\\nKatastrofalna jakość Powietrza\\n" >> /tmp/airly | |
else | |
echo -e "\\nNIE MOGĘ WYDAĆ WERDYKTU :/\\n" | |
fi | |
# | |
cat /tmp/airly | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output/Format wyjściowy:
Pomiar GDZIEŚ_TAM