This repository has been archived on 2024-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
sensebox-query/sensebox-query
2018-08-07 21:46:50 +02:00

22 lines
682 B
Bash
Executable file

#!/bin/bash
function get_data {
local -r URL="https://api.opensensemap.org/boxes/59d7de4c66f66a0010797868/sensors"
local JSON="$(curl --silent "$URL" | tr '{[,' "\n")"
echo "$JSON" | grep -e "title" -e "unit" -e "value" -e "createdAt" | cut -d'"' -f4
}
function print_table {
while mapfile -n 4 -t line && ((${#line[@]})); do
# parse timestamp with date
line[3]="$(date --date="${line[3]}")"
# join lines with |
{ local IFS='|'; echo "${line[*]}"; }
done | column \
--table --separator='|' --table-columns="Measurement,Unit,Value,Date" \
--table-order="1,3,2,4" --table-right="Value"
}
get_data | print_table