Skip to content

Commit 7ee5c5c

Browse files
committed
Adding the file with all the code for the flightradar option and updating the requirements.txt to include FlightRadar24
1 parent cc642f5 commit 7ee5c5c

File tree

2 files changed

+122
-1
lines changed

2 files changed

+122
-1
lines changed

installer/requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ img2pdf
4747
pdf2image
4848
python-nmap
4949
yeelight
50-
haversine
50+
haversine
51+
FlightRadarAPI

jarviscli/plugins/flightradar.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from plugin import plugin
2+
from FlightRadar24.api import FlightRadar24API
3+
flightapi = FlightRadar24API()
4+
5+
6+
@plugin("flightradar")
7+
def flightradar(jarvis, s):
8+
flightapi = FlightRadar24API()
9+
10+
airports = flightapi.get_airports()
11+
airlines = flightapi.get_airlines()
12+
flights = flightapi.get_flights()
13+
14+
option = int(input("What do you want to do:\n 1) Check Airline flights\n 2) Check Flight between Destinations\n 3) Track flight\nPlease chose between(1, 2, 3): "))
15+
16+
if option == 1:
17+
get_input_method = int(input("How will you give the name of the airline:\n 1) By icao\n 2) By airline name\nPlease chose between(1, 2): "))
18+
if get_input_method == 1:
19+
airline_icao = input("What is the airlines icao: ")
20+
if airline_icao != "":
21+
airline_planes = flightapi.get_flights(airline = airline_icao.upper())
22+
airline_flights = []
23+
for plane in airline_planes:
24+
if plane.altitude != 0:
25+
airline_flights.append(plane)
26+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10} ".format("ICAO", "Registration", "Origin Airport", "Destination Airport", "latitude", "longitude", "time"))
27+
for flight in airline_flights:
28+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format(flight.airline_icao, flight.registration, flight.origin_airport_iata, flight.destination_airport_iata, flight.latitude, flight.longitude, flight.time))
29+
else:
30+
jarvis.say("Enter a ICAO")
31+
32+
elif get_input_method == 2:
33+
airline_name = input("What is the airlines Name: ")
34+
if airline_name == "":
35+
jarvis.say("Enter a Airline name")
36+
run = False
37+
for airline in airlines:
38+
if airline["Name"].lower() == airline_name.lower():
39+
airline_icao = airline["ICAO"]
40+
run = True
41+
break
42+
if run:
43+
airline_planes = flightapi.get_flights(airline = airline_icao)
44+
airline_flights = []
45+
for plane in airline_planes:
46+
if plane.altitude != 0:
47+
airline_flights.append(plane)
48+
jarvis.say(" {:^5} {:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format("Name","ICAO", "Registration", "Origin Airport", "Destination Airport", "latitude", "longitude", "time"))
49+
for flight in airline_flights:
50+
jarvis.say("{:^5} {:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format(airline_name, flight.airline_icao, flight.registration, flight.origin_airport_iata, flight.destination_airport_iata, flight.latitude, flight.longitude, flight.time))
51+
else:
52+
jarvis.say("No airline found")
53+
else:
54+
jarvis.say("Enter a vaild option")
55+
56+
elif option == 2:
57+
get_input_method = int(input("How will you give the name of the airports:\n 1) By iata\n 2) By airport name\nPlease chose between(1, 2): "))
58+
if get_input_method == 1:
59+
origin_airport_iata = input("What is the origin airport iata: ")
60+
destination_airport_iata = input("What is the destination airport iata: ")\
61+
62+
if origin_airport_iata != destination_airport_iata:
63+
route_flights = []
64+
for plane in flights:
65+
if (plane.origin_airport_iata == origin_airport_iata) and (plane.destination_airport_iata == destination_airport_iata):
66+
route_flights.append(plane)
67+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format("ICAO", "Registration", "Origin Airport", "Destination Airport", "latitude", "longitude", "time"))
68+
for flight in route_flights:
69+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format(flight.airline_icao, flight.registration, flight.origin_airport_iata, flight.destination_airport_iata, flight.latitude, flight.longitude, flight.time))
70+
71+
72+
elif get_input_method == 2:
73+
origin_airport_name = input("What is the origin airport name: ")
74+
destination_airport_name = input("What is the destination airport name: ")
75+
76+
if origin_airport_name != destination_airport_name:
77+
run = False
78+
orun = False
79+
drun = False
80+
for airport in airports:
81+
if airport["name"].lower() == origin_airport_name.lower():
82+
origin_airport_iata = airport["iata"]
83+
orun = True
84+
elif airport["name"].lower() == destination_airport_name.lower():
85+
destination_airport_iata = airport["iata"]
86+
drun = True
87+
if orun and drun:
88+
run = True
89+
break
90+
if run:
91+
jarvis.say(destination_airport_iata, origin_airport_iata)
92+
93+
route_flights = []
94+
for plane in flights:
95+
if (plane.origin_airport_iata == origin_airport_iata) and (plane.destination_airport_iata == destination_airport_iata):
96+
route_flights.append(plane)
97+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format("ICAO", "Registration", "Origin Airport", "Destination Airport", "latitude", "longitude", "time"))
98+
for flight in route_flights:
99+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format(flight.airline_icao, flight.registration, flight.origin_airport_iata, flight.destination_airport_iata, flight.latitude, flight.longitude, flight.time))
100+
else:
101+
if not orun and not drun:
102+
jarvis.say("Neither origin and destination airports were found")
103+
elif not orun:
104+
jarvis.say("The origin airport wasn't found")
105+
elif not drun:
106+
jarvis.say("The destination airport wasn't found")
107+
else:
108+
jarvis.say("Enter a vaild option")
109+
110+
elif option == 3:
111+
flight_resgitration = input("What is the airplane resgistration: ")
112+
113+
for flight in flights:
114+
if flight.registration == flight_resgitration:
115+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format("ICAO", "Registration", "Origin Airport", "Destination Airport", "latitude", "longitude", "time"))
116+
jarvis.say("{:^5} {:^10} {:^20} {:^22} {:^10} {:^10} {:^10}".format(flight.airline_icao, flight.registration, flight.origin_airport_iata, flight.destination_airport_iata, flight.latitude, flight.longitude, flight.time))
117+
break
118+
119+
else:
120+
jarvis.say("Enter a vaild option")

0 commit comments

Comments
 (0)