Created
March 28, 2024 06:01
-
-
Save sumanchapai/3702366a5394c4e6a3c5a96ba1dab29a to your computer and use it in GitHub Desktop.
shell function to see buddha air flight status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buddha() { | |
# Set PKR and KTM as the default arguments, converting airports to uppercase | |
local FROM=$(echo "${1:-PKR}" | tr "[:lower:]" "[:upper:]") | |
local TO=$(echo "${2:-KTM}" | tr "[:lower:]" "[:upper:]") | |
# Convert the airports to uppercase | |
local FROM=echo $FROM | tr "[:lower:]" "[:upper:]" | |
local LOWER="" | |
local FETCH_URL="https://admin.buddhaair.com/api/flight-status/${FROM}/${TO}" | |
awk ' | |
function contents_inside_html_tag(s) { | |
# get the first item as a result of split by </ | |
# save the result | |
# return second item as a result of split by > | |
split(s, x, "</") | |
split(x[1], y, ">") | |
return y[2] | |
} | |
BEGIN { | |
printf("%-10s%-20s%-20s%-8s%-16s%-20s%-s\n", | |
"Number", | |
"Origin", | |
"Destination", | |
"Time", | |
"RevisedTime", | |
"Status", | |
"Remarks") | |
} | |
/<FlightNo/ {printf("%-10s", contents_inside_html_tag($0))} | |
/<Departure/ {printf("%-20s", contents_inside_html_tag($0))} | |
/<Arrival/ {printf("%-20s", contents_inside_html_tag($0))} | |
/<FlightTime/ {printf("%-8s", contents_inside_html_tag($0))} | |
/<RevisedTime/ {printf("%-16s", contents_inside_html_tag($0))} | |
/<\/FlightStatus/ {printf("%-20s", contents_inside_html_tag($0))} | |
/<FlightRemarks/ {printf("%-s", contents_inside_html_tag($0))} | |
/<\/Flight>/ {printf("\n")} | |
' <(curl -s ${FETCH_URL}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
produces the output: