2019-12-09 20:38:25 +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:38:25 +02:00
|
|
|
async def matrix_message(self, bot, room, event):
|
|
|
|
args = event.body.split()
|
|
|
|
if len(args) == 2:
|
|
|
|
icao = args[1]
|
2020-01-02 14:27:29 +02:00
|
|
|
metar_url = "https://tgftp.nws.noaa.gov/data/observations/metar/stations/" + \
|
2020-02-02 23:08:15 +02:00
|
|
|
icao.upper() + ".TXT"
|
2019-12-09 20:38:25 +02:00
|
|
|
response = urllib.request.urlopen(metar_url)
|
|
|
|
lines = response.readlines()
|
|
|
|
await bot.send_text(room, lines[1].decode("utf-8").strip())
|
|
|
|
else:
|
|
|
|
await bot.send_text(room, 'Usage: !metar <icao code>')
|
|
|
|
|
|
|
|
def help(self):
|
2020-02-02 23:08:15 +02:00
|
|
|
return ('Metar data access (usage: !metar <icao code>)')
|