aboutsummaryrefslogtreecommitdiff
path: root/templates/.bin/metar
blob: e81a0285ee1c4e9aa0661ca0449ab7fe7c4c18ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

say=0
jq="/usr/bin/jq"
if [[ ! -x "$jq" && -x "/usr/local/bin/jq" ]]; then
  jq="/usr/local/bin/jq"
fi

while [ $# -gt 0 ]; do
  case "$1" in
  -s|--say)
    say=1
    ;;
  -*)
    echo "Unknown option flag: $1"
    exit 1
    ;;
  *)
    station=$(echo -n "$1" | tr "a-z" "A-Z")
    ;;
  esac
  shift
done
token=$(pass show avwx-token)
json=$(curl -s -H "Authorization: ${token}" "https://avwx.rest/api/metar/${station:-KBOS}?options=speech")
if [ $say -gt 0 ]; then
  echo "$json" | "$jq" --raw-output '.speech' 2>&1 | say
else
  echo "$json" | "$jq" --raw-output '.raw' 2>&1
fi