Skip to content

Instantly share code, notes, and snippets.

@pwittchen
Last active December 22, 2017 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwittchen/6eda564ad3a71ca1d57ffc28c0bd7aef to your computer and use it in GitHub Desktop.
Save pwittchen/6eda564ad3a71ca1d57ffc28c0bd7aef to your computer and use it in GitHub Desktop.
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