Skip to content

Instantly share code, notes, and snippets.

@sumanchapai
Created March 28, 2024 06:01
Show Gist options
  • Save sumanchapai/3702366a5394c4e6a3c5a96ba1dab29a to your computer and use it in GitHub Desktop.
Save sumanchapai/3702366a5394c4e6a3c5a96ba1dab29a to your computer and use it in GitHub Desktop.
shell function to see buddha air flight status
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})
}
@sumanchapai
Copy link
Author

Usage:

buddha pkr ktm

produces the output:

Number    Origin              Destination         Time    RevisedTime     Status              Remarks
U4-1656   POKHARA             KATHMANDU           07:35   14:00           DELAY                POKHARA AIRPORT CLOSED DUE TO WEATHER
U4-604    POKHARA             KATHMANDU           08:30   14:00           DELAY                POKHARA AIRPORT CLOSED DUE TO WEATHER
U4-652    POKHARA             KATHMANDU           09:00   14:00           DELAY                POKHARA AIRPORT CLOSED DUE TO WEATHER
U4-606    POKHARA             KATHMANDU           09:55   14:00           DELAY                 POKHARA AIRPORT CLOSED DUE TO WEATHER
U4-610    POKHARA             KATHMANDU           10:45   14:00           DELAY                  POKHARA AIRPORT CLOSED DUE TO WEATHER
U4-614    POKHARA             KATHMANDU           12:10   14:00           DELAY                  POKHARA AIRPORT CLOSED DUE WEATHER
U4-616    POKHARA             KATHMANDU           13:05   14:00           DELAY                  POKHARA AIRPORT CLOSED DUE WEATHER
U4-612    POKHARA             KATHMANDU           13:25   14:00           DELAY                  POKHARA AIRPORT CLOSED DUE WEATHER
U4-620    POKHARA             KATHMANDU           14:10   14:10                                
U4-618    POKHARA             KATHMANDU           14:25   14:25                                
U4-656    POKHARA             KATHMANDU           15:40   15:40                                
U4-658    POKHARA             KATHMANDU           16:25   16:25                                
U4-660    POKHARA             KATHMANDU           16:50   16:50           ONTIME               
U4-662    POKHARA             KATHMANDU           18:45   18:45                                
                    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment