send the sequence to the UI
This commit is contained in:
@@ -1,9 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from json import JSONEncoder
|
||||||
|
from requests.adapters import HTTPAdapter
|
||||||
|
from requests.packages.urllib3.util.retry import Retry
|
||||||
|
from requests.structures import CaseInsensitiveDict
|
||||||
|
|
||||||
from aman.config.Server import Server
|
from aman.config.Server import Server
|
||||||
from aman.types.Inbound import Inbound
|
|
||||||
|
class InboundEncoder(JSONEncoder):
|
||||||
|
def default(self, o):
|
||||||
|
pta = str(o.PlannedArrivalTime)
|
||||||
|
delimiter = pta.find('.')
|
||||||
|
if -1 == delimiter:
|
||||||
|
delimiter = pta.find('+')
|
||||||
|
return { 'callsign' : o.Callsign, 'runway' : o.PlannedRunway.Name, 'pta' : pta[0:delimiter] }
|
||||||
|
|
||||||
class WebUI:
|
class WebUI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -20,11 +34,31 @@ class WebUI:
|
|||||||
def release(self):
|
def release(self):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def createSession():
|
||||||
|
# prepare the session
|
||||||
|
session = requests.Session()
|
||||||
|
retry = Retry(total=1, read=1, connect=1)
|
||||||
|
adapter = HTTPAdapter(max_retries=retry)
|
||||||
|
session.mount('http://', adapter)
|
||||||
|
session.mount('https://', adapter)
|
||||||
|
return session
|
||||||
|
|
||||||
|
def requestConfiguration(self, airport):
|
||||||
|
return
|
||||||
|
|
||||||
def sendSequence(self, airport, inbounds):
|
def sendSequence(self, airport, inbounds):
|
||||||
sequence = []
|
# prepare the HTTP header and session
|
||||||
|
headers = CaseInsensitiveDict()
|
||||||
|
headers['Accept'] = 'application/json'
|
||||||
|
headers['Content-Type'] = 'application/json'
|
||||||
|
session = WebUI.createSession()
|
||||||
|
|
||||||
for inbound in inbounds:
|
# prepare the relevant information
|
||||||
sequence.append(str(inbound.toJSON()))
|
url = self.Config.WebUiUrl + self.Config.WebUiSequenceNotification
|
||||||
|
data = json.dumps({ 'airport': airport, 'sequence': inbounds }, ensure_ascii=True, cls=InboundEncoder)
|
||||||
|
|
||||||
# TODO send to the server
|
# send to the server
|
||||||
#print(json.dumps({ 'airport': airport, 'sequence': sequence }, ensure_ascii=True))
|
try:
|
||||||
|
response = session.patch(url, headers=headers, data=data, timeout=2)
|
||||||
|
except requests.exceptions.ConnectTimeout:
|
||||||
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user