diff --git a/modules/taf.py b/modules/taf.py new file mode 100644 index 0000000..35d4fe2 --- /dev/null +++ b/modules/taf.py @@ -0,0 +1,21 @@ +import os +import urllib.request + +class MatrixModule: + async def matrix_message(self, bot, room, event): + args = event.body.split() + if len(args) == 2: + icao = args[1] + taf_url = "https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=tafs&requestType=retrieve&format=csv&hoursBeforeNow=3&timeType=issue&mostRecent=true&stationString=" + icao.upper() + response = urllib.request.urlopen(taf_url) + lines = response.readlines() + if len(lines) > 6: + taf = lines[6].decode("utf-8").split(',')[0] + await bot.send_text(room, taf.strip()) + else: + await bot.send_text(room, 'Cannot find taf for ' + icao) + else: + await bot.send_text(room, 'Usage: !taf ') + + def help(self): + return('Taf data access (usage: !taf )')