21 lines
682 B
Bash
Executable file
21 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
|