From 6c5133f140c8358eb39297b9271e7f7c8ef74c7f Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sun, 17 Jan 2021 22:32:48 -0500 Subject: [PATCH] Added MUF and foF2 maps Fixes #311 --- exts/propagation.py | 60 +++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + templates/data/options.py | 16 ++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 exts/propagation.py diff --git a/exts/propagation.py b/exts/propagation.py new file mode 100644 index 0000000..43efd64 --- /dev/null +++ b/exts/propagation.py @@ -0,0 +1,60 @@ +""" +Propagation extension for qrm +--- +Copyright (C) 2019-2020 Abigail Gold, 0x5c + +This file is part of qrm2 and is released under the terms of +the GNU General Public License, version 2. +""" + + +from io import BytesIO + +import aiohttp +import cairosvg + +import discord +import discord.ext.commands as commands + +import common as cmn + + +class PropagationCog(commands.Cog): + muf_url = "https://prop.kc2g.com/renders/current/mufd-normal-now.svg" + fof2_url = "https://prop.kc2g.com/renders/current/fof2-normal-now.svg" + + def __init__(self, bot): + self.bot = bot + self.session = aiohttp.ClientSession(connector=bot.qrm.connector) + + @commands.command(name="mufmap", aliases=["muf"], category=cmn.cat.weather) + async def mufmap(self, ctx: commands.Context): + """Shows a world map of the Maximum Usable Frequency (MUF).""" + async with ctx.typing(): + async with self.session.get(self.muf_url) as r: + svg = await r.read() + out = BytesIO(cairosvg.svg2png(bytestring=svg)) + file = discord.File(out, "muf_map.png") + embed = cmn.embed_factory(ctx) + embed.title = "Maximum Usable Frequency Map" + embed.description = "Image from [prop.kc2g.com](https://prop.kc2g.com/)\nData sources listed on the page." + embed.set_image(url="attachment://muf_map.png") + await ctx.send(file=file, embed=embed) + + @commands.command(name="fof2map", aliases=["fof2", "critfreq"], category=cmn.cat.weather) + async def fof2map(self, ctx: commands.Context): + """Shows a world map of the Critical Frequency (foF2).""" + async with ctx.typing(): + async with self.session.get(self.fof2_url) as r: + svg = await r.read() + out = BytesIO(cairosvg.svg2png(bytestring=svg)) + file = discord.File(out, "fof2_map.png") + embed = cmn.embed_factory(ctx) + embed.title = "Critical Frequency (foF2) Map" + embed.description = "Image from [prop.kc2g.com](https://prop.kc2g.com/)\nData sources listed on the page." + embed.set_image(url="attachment://fof2_map.png") + await ctx.send(file=file, embed=embed) + + +def setup(bot: commands.Bot): + bot.add_cog(PropagationCog(bot)) diff --git a/requirements.txt b/requirements.txt index d94c499..b950af8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,3 +3,4 @@ ctyparser~=2.0 beautifulsoup4 lxml pytz +cairosvg diff --git a/templates/data/options.py b/templates/data/options.py index 610c19e..e4d66f7 100644 --- a/templates/data/options.py +++ b/templates/data/options.py @@ -30,7 +30,21 @@ debug = False owners_uids = (200102491231092736,) # The extensions to load when running the bot. -exts = ["ae7q", "base", "fun", "grid", "ham", "image", "lookup", "morse", "qrz", "study", "weather", "dbconv"] +exts = [ + "ae7q", + "base", + "fun", + "grid", + "ham", + "image", + "lookup", + "morse", + "qrz", + "study", + "weather", + "dbconv", + "propagation", +] # Either "time", "random", or "fixed" (first item in statuses) status_mode = "fixed"