diff --git a/README.md b/README.md index f9973a2..c98df12 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ Aviation weather TAF service access. * !taf eftp +### NOTAM + +Aviation NOTAM data access. Currently supports only Finnish airports - implement other countries where +data is available. + +* !notam efjm + ### Teamup Can access Teamup ( https://teamup.com/ ) calendar. Teamup has nice API and is easier to set up than Google so diff --git a/modules/common/pollingservice.py b/modules/common/pollingservice.py index 78e26a3..c549afc 100644 --- a/modules/common/pollingservice.py +++ b/modules/common/pollingservice.py @@ -8,7 +8,7 @@ class PollingService: self.known_ids = set() self.account_rooms = dict() # Roomid -> [account, account..] self.next_poll_time = dict() # Roomid -> datetime, None = not polled yet - self.service_name = "Service" + self.service_name = "Service" async def matrix_poll(self, bot, pollcount): if len(self.account_rooms): diff --git a/modules/notam.py b/modules/notam.py new file mode 100644 index 0000000..6e005d4 --- /dev/null +++ b/modules/notam.py @@ -0,0 +1,45 @@ +import urllib.request +import re + + +class MatrixModule: + async def matrix_message(self, bot, room, event): + args = event.body.split() + if len(args) == 2 and len(args[1]) == 4: + icao = args[1].upper() + notam = self.get_notam(icao) + await bot.send_text(room, notam) + else: + await bot.send_text(room, 'Usage: !notam ') + + def help(self): + return('NOTAM data access (usage: !notam ) - Currently Finnish airports only') + +# TODO: This handles only finnish airports. Implement support for other countries. + def get_notam(self, icao): + if not icao.startswith('EF'): + return('Only Finnish airports supported currently, sorry.') + + icao_first_letter = icao[2] + if icao_first_letter < 'M': + notam_url = "https://www.ais.fi/ais/bulletins/envfra.htm" + else: + notam_url = "https://www.ais.fi/ais/bulletins/envfrm.htm" + + response = urllib.request.urlopen(notam_url) + lines = response.readlines() + lines = b''.join(lines) + lines = lines.decode("ISO-8859-1") + # Strip EN-ROUTE from end + lines = lines[0:lines.find('')] + + startpos = lines.find('') + if startpos > -1: + endpos = lines.find('

', startpos) + if endpos == -1: + endpos = len(lines) + notam = lines[startpos:endpos] + notam = re.sub('<[^<]+?>', ' ', notam) + if len(notam) > 4: + return notam + return f'Cannot parse notam for {icao} at {notam_url}'