-
Notifications
You must be signed in to change notification settings - Fork 0
/
Message.py
113 lines (90 loc) · 4.56 KB
/
Message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from datetime import datetime
import json
import jinja2
import re
import urllib.request
from WaypointDB import Waypoint
from WaypointDB import WaypointDB
class Message:
def __init__(self,id,timestamp,text,mtype,json_content):
self.timestamp = timestamp
self.text = text
self.json_content = json_content
self.mtype = mtype
self.id = id
self.rwy = 'UNKNOWN'
self.takeoff_waypoint = 'UNKNOWN'
self.dest = 'UNKNOWN'
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/html/eAIP/EH-AD-2.EHAM-en-GB.html#eham-ad-2.24"
self.is_Schipol = True
self.route = ['UNKNOWN']
def parseRoute(self,route_text):
if re.search(r"[A-Z]{5}\.[A-Z]{5}\.[A-Z]{5}", route_text):
self.route = re.findall(r"\.([0-9A-Z]{5}|[A-Z]{4}|[A-Z]{3})",route_text)
if re.search(r",[0-9]{5}\.[A-Z]{5},[0-9]{5}\.[A-Z]{5},[0-9]{5}\.[A-Z]{5}", route_text):
self.route = re.findall(r",[0-9]{5}\.([0-9A-Z]{5}|[A-Z]{4}|[A-Z]{3})",route_text)
if re.search(r",[0-9]{6},[0-9A-Z]{6}\.[A-Z]{5},[0-9]{6},[0-9A-Z]{6}\.[0-9A-Z]{5}",route_text):
self.route = re.findall(r",[0-9]{6},[0-9A-Z]{6}\.([0-9A-Z]{5}|[A-Z]{4}|[A-Z]{3})",route_text)
if re.search(r"\.\.[A-Z]{5}\.\.[A-Z]{5}\.", route_text):
self.route = re.findall(r"\.\.([0-9A-Z]{5}|[A-Z]{4}|[A-Z]{3})\.",route_text)
def getRouteSpaces(self):
return_string = ''
for w in self.route:
return_string+=str(w) + " "
return return_string
def getRouteJSON(self, waypointsDB):
json_data = []
for waypoint_name in self.route:
waypoint = waypointsDB.getWaypointByName(waypoint_name)
if waypoint.name != 'NULL':
json_waypoint = {}
json_waypoint["name"] = waypoint.name
json_waypoint["lat"] = str(waypoint.lat)
json_waypoint["lon"] = str(waypoint.lon)
json_data.append(json_waypoint)
return json.dumps(json_data)
def getRouteHTML(self, waypointsDB):
templateLoader = jinja2.FileSystemLoader(searchpath="./templates")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template('route_template_2.html')
return template.render(text = self.getRouteSpaces())
def createLink(self):
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/graphics/eAIP/EH-AD-2.EHAM-SID-"+self.rwy+".pdf"
if self.rwy == '24':
if 'VALK' in self.takeoff_waypoint or 'BERG' in self.takeoff_waypoint:
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/graphics/eAIP/EH-AD-2.EHAM-SID-"+self.rwy+"-2.pdf"
else:
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/graphics/eAIP/EH-AD-2.EHAM-SID-"+self.rwy+"-1.pdf"
if self.rwy == '36L':
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/graphics/eAIP/EH-AD-2.EHAM-SID-"+self.rwy+"-1.pdf"
if self.rwy == '06':
self.link = "https://www.lvnl.nl/eaip/2021-01-14-AIRAC/graphics/eAIP/EH-AD-2.EHAM-SID-"+self.rwy+"-1.pdf"
return self.link
def getHTMLMessage(self):
templateLoader = jinja2.FileSystemLoader(searchpath="./templates")
templateEnv = jinja2.Environment(loader=templateLoader)
if self.mtype == "text":
template = templateEnv.get_template('text_message_template.html')
return template.render(msg = self)
if self.mtype == "arinc622" or self.mtype == "libacars":
template = templateEnv.get_template('arinc622_message_template.html')
return template.render(msg = self)
if self.mtype == 'route':
template = templateEnv.get_template('route_message_template.html')
return template.render(msg = self)
if self.mtype == 'clearance':
template = templateEnv.get_template('clearance_message_template.html')
return template.render(msg = self)
if self.mtype == 'takeoff':
template = templateEnv.get_template('takeoff_message_template.html')
return template.render(msg = self)
template = templateEnv.get_template('text_message_template.html')
return template.render(msg = self)
def get_text(self):
return self.text
def getJson(self):
return json.dumps(self.json_content)
def getType(self):
return self.mtype
def get_timestamp(self):
return datetime.fromtimestamp(self.timestamp).strftime("%d-%m-%y %H:%M:%S")