hemppa/modules/taf.py

24 lines
949 B
Python
Raw Normal View History

2019-12-09 20:41:30 +02:00
import urllib.request
2020-02-02 23:08:15 +02:00
from modules.common.module import BotModule
2020-01-02 14:27:29 +02:00
2020-02-02 23:08:15 +02:00
class MatrixModule(BotModule):
2019-12-09 20:41:30 +02:00
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 <icao code>')
2020-01-02 14:27:29 +02:00
2019-12-09 20:41:30 +02:00
def help(self):
2020-02-02 23:08:15 +02:00
return ('Taf data access (usage: !taf <icao code>)')