From 5fe82eaf98e27656840ece36c96092b6a0d86823 Mon Sep 17 00:00:00 2001 From: Asa Venton Date: Mon, 2 Nov 2020 18:06:41 +0000 Subject: Swap all airports to IATA codes. Explicity state if the time output is scheduled, estimated or actual. Fix not swapping between origin and dest in one of the loops in _airport. --- flightquery.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/flightquery.sh b/flightquery.sh index 19ea694..6a84d54 100755 --- a/flightquery.sh +++ b/flightquery.sh @@ -46,9 +46,9 @@ _airport() { # Get origin/destination, airline and IATA flight number if [[ $direction == "Origin" ]] then - airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.airport') + airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.iata') else - airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.airport') + airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.iata') fi airline=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].airline.name') flightIATA=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].flight.iata') @@ -57,32 +57,45 @@ _airport() { if [[ $(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.actual') != "null" ]] then takeoff=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.actual') + deptTimeType="ATD" elif [[ $(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.estimated') != "null" ]] then takeoff=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.estimated') + deptTimeType="ETD" else takeoff=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.scheduled') + deptTimeType="STD" fi if [[ $(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.actual') != "null" ]] then landing=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.actual') + arrTimeType="ATA" elif [[ $(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.estimated') != "null" ]] then landing=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.estimated') + arrTimeType="ETA" else landing=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.scheduled') + arrTimeType="STA" fi # Append to $output - output="$output $airline $flightIATA $direction: $airport Takeoff: $(date -d $takeoff +"%d/%m/%Y %H:%M") Landed: $(date -d $landing +"%d/%m/%Y %H:%M") |" + output="$output $airline, $flightIATA, $direction: $airport, $deptTimeType: $(date -d $takeoff +"%d/%m/%Y %H:%M"), $arrTimeType: $(date -d $landing +"%d/%m/%Y %H:%M") |" done # Build output string of the three arrivals immediately after the current time for i in {0..2} do # Get origin/destination, airline and IATA flight number - origin=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.airport') + if [[ $direction == "Origin" ]] + then + airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].departure.iata') + else + airport=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].arrival.iata') + fi + airline=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].airline.name') + flightIATA=$(echo $flightsBefore | jq -r --arg i $i '.[$i | tonumber].flight.iata') airline=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].airline.name') flightIATA=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].flight.iata') @@ -90,25 +103,31 @@ _airport() { if [[ $(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.actual') != "null" ]] then takeoff=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.actual') + deptTimeType="ATD" elif [[ $(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.estimated') != "null" ]] then takeoff=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.estimated') + deptTimeType="ETD" else takeoff=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].departure.scheduled') + deptTimeType="STD" fi if [[ $(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].arrival.actual') != "null" ]] then landing=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].arrival.actual') + arrTimeType="ATA" elif [[ $(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].arrival.estimated') != "null" ]] then landing=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].arrival.estimated') + arrTimeType="ETA" else landing=$(echo $flightsAfter | jq -r --arg i $i '.[$i | tonumber].arrival.scheduled') + arrTimeType="STA" fi # Append to $output - output="$output $airline $flightIATA Origin: $origin Takeoff: $(date -d $takeoff +"%d/%m/%Y %H:%M") Landing: $(date -d $landing +"%d/%m/%Y %H:%M") |" + output="$output $airline, $flightIATA, $direction: $airport, $deptTimeType: $(date -d $takeoff +"%d/%m/%Y %H:%M"), $arrTimeType: $(date -d $landing +"%d/%m/%Y %H:%M") |" done # remove trailing pipe -- cgit v1.2.3