diff options
author | Asa Venton <asav1410@gmail.com> | 2020-11-02 18:06:41 +0000 |
---|---|---|
committer | Asa Venton <asav1410@gmail.com> | 2020-11-02 18:06:41 +0000 |
commit | 5fe82eaf98e27656840ece36c96092b6a0d86823 (patch) | |
tree | fb7d79d8c11c951790668e92ae8e2e7bcef6c2c9 | |
parent | cdc3152aa3c16d640f225ece8bc8391a22577024 (diff) |
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.
-rwxr-xr-x | flightquery.sh | 29 |
1 files 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 |