FlightRadarAPI 1.3.0__tar.gz → 1.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadar24/__init__.py +1 -1
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadar24/api.py +89 -45
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadar24/core.py +1 -0
- FlightRadarAPI-1.3.1/FlightRadar24/errors.py +2 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadar24/request.py +4 -3
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadarAPI.egg-info/PKG-INFO +1 -1
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadarAPI.egg-info/SOURCES.txt +1 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/PKG-INFO +1 -1
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadar24/flight.py +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadarAPI.egg-info/dependency_links.txt +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadarAPI.egg-info/requires.txt +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/FlightRadarAPI.egg-info/top_level.txt +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/LICENSE +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/README.md +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/setup.cfg +0 -0
- {FlightRadarAPI-1.3.0 → FlightRadarAPI-1.3.1}/setup.py +0 -0
|
@@ -1,54 +1,44 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
2
3
|
|
|
3
4
|
from .core import Core
|
|
5
|
+
from .errors import LoginError
|
|
4
6
|
from .flight import Flight
|
|
5
7
|
from .request import APIRequest
|
|
6
8
|
|
|
7
|
-
from deprecated import deprecated
|
|
8
|
-
from typing import Any, Dict, List, Optional, Tuple
|
|
9
|
-
|
|
10
9
|
|
|
11
10
|
class FlightRadar24API(object):
|
|
12
11
|
"""
|
|
13
|
-
|
|
12
|
+
Main class of the FlightRadarAPI
|
|
14
13
|
"""
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def login(self, user: str, password: str) -> Dict:
|
|
33
|
-
# Log in with Flightradar24 Premium user credentials
|
|
34
|
-
data = {
|
|
35
|
-
"email": user,
|
|
36
|
-
"password": password,
|
|
37
|
-
"remember": "true",
|
|
38
|
-
"type": "web"
|
|
15
|
+
def __init__(self, user: Optional[str] = None, password: Optional[str] = None):
|
|
16
|
+
self.__real_time_flight_tracker_config = {
|
|
17
|
+
"faa": "1",
|
|
18
|
+
"satellite": "1",
|
|
19
|
+
"mlat": "1",
|
|
20
|
+
"flarm": "1",
|
|
21
|
+
"adsb": "1",
|
|
22
|
+
"gnd": "1",
|
|
23
|
+
"air": "1",
|
|
24
|
+
"vehicles": "1",
|
|
25
|
+
"estimated": "1",
|
|
26
|
+
"maxage": "14400",
|
|
27
|
+
"gliders": "1",
|
|
28
|
+
"stats": "1",
|
|
29
|
+
"limit": "5000"
|
|
39
30
|
}
|
|
31
|
+
self.__login_data: Optional[Dict] = None
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return request.get_content()
|
|
33
|
+
if user is not None and password is not None:
|
|
34
|
+
self.login(user, password)
|
|
45
35
|
|
|
46
36
|
def get_airlines(self) -> List[Dict]:
|
|
47
37
|
"""
|
|
48
38
|
Return a list with all airlines.
|
|
49
39
|
"""
|
|
50
|
-
|
|
51
|
-
return
|
|
40
|
+
response = APIRequest(Core.airlines_data_url, headers = Core.json_headers)
|
|
41
|
+
return response.get_content()["rows"]
|
|
52
42
|
|
|
53
43
|
def get_airline_logo(self, iata: str, icao: str) -> Optional[Tuple[bytes, str]]:
|
|
54
44
|
"""
|
|
@@ -78,15 +68,15 @@ class FlightRadar24API(object):
|
|
|
78
68
|
|
|
79
69
|
:param code: ICAO or IATA of the airport.
|
|
80
70
|
"""
|
|
81
|
-
|
|
82
|
-
return
|
|
71
|
+
response = APIRequest(Core.airport_data_url.format(code), headers = Core.json_headers)
|
|
72
|
+
return response.get_content()["details"]
|
|
83
73
|
|
|
84
74
|
def get_airports(self) -> List[Dict]:
|
|
85
75
|
"""
|
|
86
76
|
Return a list with all airports.
|
|
87
77
|
"""
|
|
88
|
-
|
|
89
|
-
return
|
|
78
|
+
response = APIRequest(Core.airports_data_url, headers = Core.json_headers)
|
|
79
|
+
return response.get_content()["rows"]
|
|
90
80
|
|
|
91
81
|
def get_bounds(self, zone: Dict[str, float]) -> str:
|
|
92
82
|
"""
|
|
@@ -94,7 +84,7 @@ class FlightRadar24API(object):
|
|
|
94
84
|
|
|
95
85
|
:param zone: Dictionary containing the following keys: tl_y, tl_x, br_y, br_x
|
|
96
86
|
"""
|
|
97
|
-
return "{},{},{},{}".format(zone["tl_y"], zone["br_y"]
|
|
87
|
+
return "{},{},{},{}".format(zone["tl_y"], zone["br_y"], zone["tl_x"], zone["br_x"])
|
|
98
88
|
|
|
99
89
|
def get_country_flag(self, country: str) -> Optional[Tuple[bytes, str]]:
|
|
100
90
|
"""
|
|
@@ -118,8 +108,8 @@ class FlightRadar24API(object):
|
|
|
118
108
|
"""
|
|
119
109
|
Return the flight details from Data Live Flightradar24.
|
|
120
110
|
"""
|
|
121
|
-
|
|
122
|
-
return
|
|
111
|
+
response = APIRequest(Core.flight_data_url.format(flight_id), headers = Core.json_headers)
|
|
112
|
+
return response.get_content()
|
|
123
113
|
|
|
124
114
|
def get_flights(self, airline: str = None, bounds: str = None, registration: str = None, aircraft_type: str = None) -> List[Flight]:
|
|
125
115
|
"""
|
|
@@ -130,7 +120,6 @@ class FlightRadar24API(object):
|
|
|
130
120
|
:param registration: aircraft registration
|
|
131
121
|
:param aircraft_type: aircraft model code. Ex: "B737"
|
|
132
122
|
"""
|
|
133
|
-
|
|
134
123
|
request_params = self.__real_time_flight_tracker_config.copy()
|
|
135
124
|
|
|
136
125
|
# Insert the parameters "airline", "bounds", "reg",and "type" in the dictionary for the request.
|
|
@@ -140,8 +129,8 @@ class FlightRadar24API(object):
|
|
|
140
129
|
if aircraft_type: request_params["type"] = aircraft_type
|
|
141
130
|
|
|
142
131
|
# Get all flights from Data Live Flightradar24.
|
|
143
|
-
|
|
144
|
-
response =
|
|
132
|
+
response = APIRequest(Core.real_time_flight_tracker_data_url, request_params, Core.json_headers)
|
|
133
|
+
response = response.get_content()
|
|
145
134
|
|
|
146
135
|
flights = []
|
|
147
136
|
|
|
@@ -153,6 +142,15 @@ class FlightRadar24API(object):
|
|
|
153
142
|
|
|
154
143
|
return flights
|
|
155
144
|
|
|
145
|
+
def get_login_data(self) -> Dict[Any, Any]:
|
|
146
|
+
"""
|
|
147
|
+
Return the user data.
|
|
148
|
+
"""
|
|
149
|
+
if not self.is_logged_in():
|
|
150
|
+
raise LoginError("You must log in to your account.")
|
|
151
|
+
|
|
152
|
+
return self.__login_data["userData"].copy()
|
|
153
|
+
|
|
156
154
|
def get_real_time_flight_tracker_config(self) -> Dict[str, str]:
|
|
157
155
|
"""
|
|
158
156
|
Return the current config of the real time flight tracker, used by get_flights() method.
|
|
@@ -163,14 +161,60 @@ class FlightRadar24API(object):
|
|
|
163
161
|
"""
|
|
164
162
|
Returns all major zones on the globe.
|
|
165
163
|
"""
|
|
166
|
-
|
|
167
|
-
zones =
|
|
164
|
+
response = APIRequest(Core.zones_data_url, headers = Core.json_headers)
|
|
165
|
+
zones = response.get_content()
|
|
168
166
|
|
|
169
167
|
if "version" in zones:
|
|
170
168
|
zones.pop("version")
|
|
171
169
|
|
|
172
170
|
return zones
|
|
173
171
|
|
|
172
|
+
def is_logged_in(self) -> bool:
|
|
173
|
+
"""
|
|
174
|
+
Check if the user is logged into the FlightRadar24 account.
|
|
175
|
+
"""
|
|
176
|
+
return self.__login_data is not None
|
|
177
|
+
|
|
178
|
+
def login(self, user: str, password: str) -> None:
|
|
179
|
+
"""
|
|
180
|
+
Log in to a FlightRadar24 account.
|
|
181
|
+
|
|
182
|
+
:param user: Your email.
|
|
183
|
+
:param password: Your password.
|
|
184
|
+
"""
|
|
185
|
+
data = {
|
|
186
|
+
"email": user,
|
|
187
|
+
"password": password,
|
|
188
|
+
"remember": "true",
|
|
189
|
+
"type": "web"
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
response = APIRequest(Core.user_login_url, headers = Core.json_headers, data = data)
|
|
193
|
+
status_code = response.get_status_code()
|
|
194
|
+
content = response.get_content()
|
|
195
|
+
|
|
196
|
+
if not str(status_code).startswith("2") or not content.get("success"):
|
|
197
|
+
if isinstance(content, dict): raise LoginError(content["message"])
|
|
198
|
+
else: raise LoginError("Your email or password is incorrect")
|
|
199
|
+
|
|
200
|
+
self.__real_time_flight_tracker_config["enc"] = response.get_cookie("_frPl")
|
|
201
|
+
|
|
202
|
+
self.__login_data = {
|
|
203
|
+
"userData": content["userData"],
|
|
204
|
+
"cookies": response.get_cookies()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
def logout(self) -> None:
|
|
208
|
+
"""
|
|
209
|
+
Log out of the Flightradar24 account.
|
|
210
|
+
"""
|
|
211
|
+
if not self.__login_data: return
|
|
212
|
+
|
|
213
|
+
APIRequest(Core.user_login_url, headers = Core.json_headers, cookies = self.__login_data["cookies"])
|
|
214
|
+
|
|
215
|
+
self.__real_time_flight_tracker_config.pop("enc")
|
|
216
|
+
self.__login_data = None
|
|
217
|
+
|
|
174
218
|
def set_real_time_flight_tracker_config(self, **config: str) -> None:
|
|
175
219
|
"""
|
|
176
220
|
Set config for the real time flight tracker, used by get_flights() method.
|
|
@@ -13,6 +13,7 @@ class Core(ABC):
|
|
|
13
13
|
|
|
14
14
|
# User login URL.
|
|
15
15
|
user_login_url = flightradar_base_url + "/user/login"
|
|
16
|
+
user_logout_url = flightradar_base_url + "/user/logout"
|
|
16
17
|
|
|
17
18
|
# Flights data URLs.
|
|
18
19
|
real_time_flight_tracker_data_url = data_cloud_base_url + "/zones/fcgi/feed.js"
|
|
@@ -15,18 +15,19 @@ class APIRequest(object):
|
|
|
15
15
|
"gzip": gzip.decompress
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
def __init__(self, url, params = {}, headers = {}, data = None):
|
|
18
|
+
def __init__(self, url, params = {}, headers = {}, data = None, cookies = None):
|
|
19
19
|
|
|
20
20
|
self.url = url
|
|
21
21
|
self.params = params
|
|
22
22
|
self.headers = headers
|
|
23
23
|
self.data = data
|
|
24
|
+
self.cookies = cookies
|
|
24
25
|
|
|
25
26
|
if data is None:
|
|
26
27
|
if params: url += "?" + "&".join(["{}={}".format(k, v) for k, v in params.items()])
|
|
27
|
-
self.__response = requests.get(url, headers = headers)
|
|
28
|
+
self.__response = requests.get(url, headers = headers, cookies = cookies)
|
|
28
29
|
else:
|
|
29
|
-
self.__response = requests.post(url,
|
|
30
|
+
self.__response = requests.post(url, headers = headers, cookies = cookies, data = data)
|
|
30
31
|
|
|
31
32
|
def get_content(self) -> Union[Dict, bytes]:
|
|
32
33
|
content = self.__response.content
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|