diff --git a/README.md b/README.md deleted file mode 100644 index 51646a5..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# sensebox-query \ No newline at end of file diff --git a/README.org b/README.org new file mode 100644 index 0000000..3c353ac --- /dev/null +++ b/README.org @@ -0,0 +1,16 @@ +* sensebox-query + +A little Bash script for querying the Sensebox installed at Krautspace. + +There are still some things to do, feel free to contribute code to solve +these issues. + +*TODO:* +- make output to shell prettier + - use conditional coloring, e.g. cold -> blue, warm -> red + - use ASCII art + - format date +- deal with errors + - curl might not be installed + - curl might fail (e.g. no connection) + - grep might not find anything diff --git a/sensebox-query b/sensebox-query new file mode 100755 index 0000000..cd9a428 --- /dev/null +++ b/sensebox-query @@ -0,0 +1,17 @@ +#!/bin/bash + +declare -r URL="https://api.opensensemap.org/boxes/59d7de4c66f66a0010797868/sensors" +declare -r TMPFILE="/tmp/sense-data" + +curl --silent "$URL" | tr '{[,' "\n" > "$TMPFILE" + +RAW_VALUES="$(grep -e "title" -e "unit" -e "value" -e "createdAt" "$TMPFILE" | cut -d'"' -f4)" + +IFS=$'\n' RAW_VALUES=(${RAW_VALUES}) + +declare -a VALUES +for i in {1..5}; do + raw_index=$(( $i * 4 - 4 )) + VALUES[$i]="${RAW_VALUES[$raw_index]}:\t${RAW_VALUES[$raw_index + 2]} ${RAW_VALUES[$raw_index + 1]}\t(as of: ${RAW_VALUES[$raw_index + 3]})" + echo -e "${VALUES[$i]}" +done