add the function to request the configuration

This commit is contained in:
Sven Czarnian
2021-11-14 10:02:21 +01:00
parent 5df1ceb204
commit f7b8f26e48

View File

@@ -9,6 +9,8 @@ from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry from requests.packages.urllib3.util.retry import Retry
from requests.structures import CaseInsensitiveDict from requests.structures import CaseInsensitiveDict
from aman.config.AirportSequencing import AirportSequencing
from aman.config.RunwaySequencing import RunwaySequencing
from aman.config.Server import Server from aman.config.Server import Server
class InboundEncoder(JSONEncoder): class InboundEncoder(JSONEncoder):
@@ -43,8 +45,57 @@ class WebUI:
session.mount('https://', adapter) session.mount('https://', adapter)
return session return session
def requestConfiguration(self, airport): def requestConfiguration(self, airport, navData):
return if airport not in navData.Runways:
return None
# prepare the HTTP header and session
headers = CaseInsensitiveDict()
headers['Accept'] = 'application/json'
headers['Content-Type'] = 'application/json'
session = WebUI.createSession()
url = self.Config.WebUiUrl + self.Config.WebUiConfigurationReceiver
data = json.dumps({ 'airport': airport }, ensure_ascii=True)
try:
response = session.get(url, headers=headers, data=data, timeout=2)
if 200 != response.status_code:
return None
except requests.exceptions.ConnectTimeout:
return None
config = json.loads(response.json())
# WebUI sent the wrong airport
if config['airport'] != airport or 0 == len(config['activeRunways']):
return None
airportConfig = AirportSequencing(airport)
airportConfig.UseMustShallMay = config['useMustShallMay']
# build the sequencing information per runway
for activeRunway in config['activeRunways']:
gngRunway = None
for runway in navData.Runways[airport]:
if runway.Name == activeRunway['runway']:
gngRunway = runway
break
# could not find the runway
if None == gngRunway:
return None
runway = RunwaySequencing(gngRunway)
runway.Spacing = int(activeRunway['spacing'])
airportConfig.activateRunway(runway)
# resolve the dependencies
for dependency in config['dependentRunways']:
if 2 == len(dependency):
airportConfig.addDependency(dependency[0], dependency[1])
return airportConfig
def sendSequence(self, airport, inbounds): def sendSequence(self, airport, inbounds):
# prepare the HTTP header and session # prepare the HTTP header and session