Added MUF and foF2 maps

Fixes #311
This commit is contained in:
0x5c 2021-01-17 22:32:48 -05:00
parent 2ae11058b2
commit 6c5133f140
No known key found for this signature in database
GPG Key ID: A57F71C3176B9581
3 changed files with 76 additions and 1 deletions

60
exts/propagation.py Normal file
View File

@ -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))

View File

@ -3,3 +3,4 @@ ctyparser~=2.0
beautifulsoup4 beautifulsoup4
lxml lxml
pytz pytz
cairosvg

View File

@ -30,7 +30,21 @@ debug = False
owners_uids = (200102491231092736,) owners_uids = (200102491231092736,)
# The extensions to load when running the bot. # 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) # Either "time", "random", or "fixed" (first item in statuses)
status_mode = "fixed" status_mode = "fixed"