FlightRadarAPI 1.3.17__tar.gz → 1.3.19__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.
@@ -13,7 +13,7 @@ https://www.flightradar24.com/terms-and-conditions
13
13
  """
14
14
 
15
15
  __author__ = "Jean Loui Bernard Silva de Jesus"
16
- __version__ = "1.3.17"
16
+ __version__ = "1.3.19"
17
17
 
18
18
  from .api import FlightRadar24API, FlightTrackerConfig
19
19
  from .entities import Airport, Entity, Flight
@@ -88,6 +88,9 @@ class FlightRadar24API(object):
88
88
  :param code: ICAO or IATA of the airport
89
89
  :param details: If True, it returns an Airport instance with detailed information.
90
90
  """
91
+ if 4 < len(code) or len(code) < 3:
92
+ raise ValueError(f"The code '{code}' is invalid. It must be the IATA or ICAO of the airport.")
93
+
91
94
  if details:
92
95
  airport = Airport()
93
96
 
@@ -100,9 +103,9 @@ class FlightRadar24API(object):
100
103
  content = response.get_content()
101
104
 
102
105
  if not content or not isinstance(content, dict) or not content.get("details"):
103
- raise AirportNotFoundError(f"Could not find an airport by the code '{code}'.");
106
+ raise AirportNotFoundError(f"Could not find an airport by the code '{code}'.")
104
107
 
105
- return Airport(info=content["details"])
108
+ return Airport(info = content["details"])
106
109
 
107
110
  def get_airport_details(self, code: str, flight_limit: int = 100, page: int = 1) -> Dict:
108
111
  """
@@ -112,6 +115,9 @@ class FlightRadar24API(object):
112
115
  :param flight_limit: Limit of flights related to the airport
113
116
  :param page: Page of result to display
114
117
  """
118
+ if 4 < len(code) or len(code) < 3:
119
+ raise ValueError(f"The code '{code}' is invalid. It must be the IATA or ICAO of the airport.")
120
+
115
121
  request_params = {"format": "json"}
116
122
 
117
123
  if self.__login_data is not None:
@@ -126,10 +132,24 @@ class FlightRadar24API(object):
126
132
  response = APIRequest(Core.api_airport_data_url, request_params, Core.json_headers, exclude_status_codes=[400,])
127
133
  content: Dict = response.get_content()
128
134
 
129
- if response.get_status_code() == 400 and isinstance(content, dict) and content.get("errors"):
130
- raise ValueError(content["errors"]["errors"]["parameters"]["limit"]["notBetween"])
135
+ if response.get_status_code() == 400 and content.get("errors"):
136
+ errors = content["errors"]["errors"]["parameters"]
137
+
138
+ if errors.get("limit"):
139
+ raise ValueError(errors["limit"]["notBetween"])
140
+
141
+ raise AirportNotFoundError(f"Could not find an airport by the code '{code}'.", errors)
142
+
143
+ result = content["result"]["response"]
144
+
145
+ # Check whether it received data of an airport.
146
+ data = result.get("airport", dict()).get("pluginData", dict())
131
147
 
132
- return content["result"]["response"]
148
+ if not "details" in data and len(data.get("runways", [])) == 0 and len(data) <= 3:
149
+ raise AirportNotFoundError(f"Could not find an airport by the code '{code}'.")
150
+
151
+ # Return the airport details.
152
+ return result
133
153
 
134
154
  def get_airports(self) -> List[Airport]:
135
155
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: FlightRadarAPI
3
- Version: 1.3.17
3
+ Version: 1.3.19
4
4
  Summary: SDK for FlightRadar24
5
5
  Project-URL: Homepage, https://github.com/JeanExtreme002/FlightRadarAPI
6
6
  Author-email: Jean Loui Bernard Silva de Jesus <jeanextreme002@gmail.com>
File without changes