Add aerodrome info to METAR. - annna - Annna the nice friendly bot. | |
git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws6… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
--- | |
commit 79fae10db6d54c7dde46003fee6e5d935fcdef4e | |
parent ab3ea84610f3b07369b0194c421c4530ebbcacfe | |
Author: eidolon <?> | |
Date: Sun, 20 Oct 2024 15:08:29 -0400 | |
Add aerodrome info to METAR. | |
Signed-off-by: Annna Robert-Houdin <[email protected]> | |
Diffstat: | |
M metar | 41 ++++++++++++++++++++++-------… | |
1 file changed, 29 insertions(+), 12 deletions(-) | |
--- | |
diff --git a/metar b/metar | |
@@ -1,30 +1,45 @@ | |
#!/bin/sh | |
iata2icao() { | |
- csv="/home/annna/bin/modules/airport-codes/data/airport-codes.csv" | |
awk -v IATA="$1" --csv 'BEGIN { IATA = toupper(IATA) } $10 == IATA { print… | |
} | |
printart() { | |
- txt="/home/annna/bin/modules/metar/ascii-planes.txt" | |
awk 'BEGIN { RS = ""; srand() } { a[NR] = $0 } END { print a[int(rand()*le… | |
} | |
+dromeinfo() { | |
+ awk -v aerodrome="$1" --csv ' | |
+ BEGIN { aerodrome = toupper(aerodrome) } NR == 1 { split($0, header) } | |
+ $1 == aerodrome || $10 == aerodrome { | |
+ for (i = 1; i <= NF; i++) | |
+ if ($i) | |
+ { | |
+ gsub(/_/, " ", header[i]) | |
+ gsub(/_/, " ", $i) | |
+ s = s sprintf(" %s %s\n", header[i]":", $i) | |
+ } | |
+ } | |
+ END { if (!s) exit; print s }' "$csv" | |
+} | |
+ | |
if ! id=$(printf '%s\n' "$1" | grep '^[A-Za-z]\{3,4\}$'); then | |
printf '%s\n' "invalid IATA/ICAO code." | |
exit 1 | |
fi | |
-if [ "${#id}" = 3 ]; then | |
- id=$(iata2icao "$id") | |
- if [ -z "$id" ]; then | |
- printf '%s\n' "invalid IATA code." | |
- exit 1 | |
- fi | |
-fi | |
- | |
fmt=decoded | |
uri="https://aviationweather.gov/api/data/metar/" | |
+txt="$HOME/bin/modules/metar/ascii-planes.txt" | |
+csv="$HOME/bin/modules/airport-codes/data/airport-codes.csv" | |
+ | |
+[ "${#id}" = 3 ] && id=$(iata2icao "$id") | |
+ | |
+if [ -z "$id" ]; then | |
+ printf '%s\n' "invalid IATA code." | |
+ exit 1 | |
+fi | |
+ | |
metar=$(curl -Ssfm 5 --data-urlencode format="$fmt" --data-urlencode ids="$id"… | |
if [ -z "$metar" ]; then | |
@@ -32,6 +47,8 @@ if [ -z "$metar" ]; then | |
exit 1 | |
fi | |
-decodeuri=$(printf '%s\n\n' "$metar" "$(printart)" | sed 's/^#//' | /br/bin/bi… | |
raw=$(printf '%s\n' "$metar" | sed -n '2s/^[^:]*: //p') | |
-printf '%s\n' "$raw ; decode: $decodeuri" | |
+art=$(printart | sed 's/^#//') | |
+info=$(dromeinfo "$id") | |
+decode=$(printf '%s\n\n' "$info" "$metar" "$art" | /br/bin/bitreich-paste) | |
+printf '%s\n' "$raw ; decode: $decode" |