Skip to content

Instantly share code, notes, and snippets.

@pwittchen pwittchen/caqi.sh
Last active Dec 22, 2017

Embed
What would you like to do?
This script is responsible for getting Common Air Quality Index (CAQI) in Poland basing on airly.eu sensors. It works with BitBar on macOS and Argos on Linux with Gnome 3.
#!/usr/bin/env bash
# This script is responsible for getting Common Air Quality Index (CAQI) in Poland basing on airly.eu sensors
# Replace API_KEY with your key, YOUR_LATITUDE and YOUR_LONGITUDE with your location
# get your API key at: https://developer.airly.eu/
# this script can be used with bitbar on macOS: https://github.com/matryer/bitbar
# and argos on Linux with Gnome 3: https://github.com/p-e-w/argos
# requirements: curl and jq (on Linux it works just with jq - on macOS I needed to add /usr/local/bin/jq)
CAQI=$(curl -s -X GET --header 'Accept: application/json' --header 'apikey: YOUR_API_KEY' \
'https://airapi.airly.eu/v1/nearestSensor/measurements?latitude=YOUR_LATITUDE&longitude=YOUR_LONGITUDE&maxDistance=1000' \
| /usr/local/bin/jq .airQualityIndex | cut -f1 -d".")
MSG="Unknown"
case 1 in
$(($CAQI <= 25))) MSG="Great!";;
$(($CAQI <= 50))) MSG="Good!";;
$(($CAQI <= 75))) MSG="Medium";;
$(($CAQI <= 100))) MSG="Bad";;
$(($CAQI >= 101))) MSG="Very Bad";;
esac
echo "CAQI: $CAQI ($MSG)"
# info about Common Air Quality Index (CAQI) in Poland
# https://www.airqualitynow.eu/pl/about_indices_definition.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.