2019-10-07 16:11:30 -04:00
|
|
|
"""
|
2019-12-07 17:26:55 -05:00
|
|
|
ae7q extension for qrm
|
2019-10-07 16:11:30 -04:00
|
|
|
---
|
2021-04-03 18:13:42 -04:00
|
|
|
Copyright (C) 2019-2021 classabbyamp, 0x5c
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2021-06-26 20:23:55 -04:00
|
|
|
SPDX-License-Identifier: LiLiQ-Rplus-1.1
|
2019-10-07 16:11:30 -04:00
|
|
|
"""
|
|
|
|
|
2020-01-31 06:50:50 -05:00
|
|
|
|
|
|
|
# Test callsigns:
|
|
|
|
# KN8U: active, restricted
|
|
|
|
# AB2EE: expired, restricted
|
|
|
|
# KE8FGB: assigned once, no restrictions
|
|
|
|
# KV4AAA: unassigned, no records
|
|
|
|
# KC4USA: reserved, no call history, *but* has application history
|
|
|
|
|
|
|
|
|
2020-01-07 05:36:09 -05:00
|
|
|
import aiohttp
|
2019-10-07 16:11:30 -04:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
2020-02-05 07:09:08 -05:00
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
|
|
|
|
2019-10-07 16:11:30 -04:00
|
|
|
|
|
|
|
class AE7QCog(commands.Cog):
|
2019-10-18 08:27:05 -04:00
|
|
|
def __init__(self, bot: commands.Bot):
|
2019-10-07 16:11:30 -04:00
|
|
|
self.bot = bot
|
2020-01-07 05:36:09 -05:00
|
|
|
self.session = aiohttp.ClientSession(connector=bot.qrm.connector)
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.group(name="ae7q", aliases=["ae"], case_insensitive=True, category=cmn.Cats.LOOKUP)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _ae7q_lookup(self, ctx: commands.Context):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up a callsign, FRN, or Licensee ID on [ae7q.com](http://ae7q.com/)."""
|
2019-10-07 16:11:30 -04:00
|
|
|
if ctx.invoked_subcommand is None:
|
2019-10-28 00:23:56 -04:00
|
|
|
await ctx.send_help(ctx.command)
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@_ae7q_lookup.command(name="call", aliases=["c"], category=cmn.Cats.LOOKUP)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _ae7q_call(self, ctx: commands.Context, callsign: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up the history of a callsign on [ae7q.com](http://ae7q.com/)."""
|
2020-01-08 17:47:34 -05:00
|
|
|
with ctx.typing():
|
|
|
|
callsign = callsign.upper()
|
2020-01-30 06:15:42 -05:00
|
|
|
desc = ""
|
2020-01-08 17:47:34 -05:00
|
|
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
|
2021-01-29 23:43:30 -05:00
|
|
|
if not callsign.isalnum():
|
2021-01-29 22:55:26 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "AE7Q History for Callsign"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.description = "Not a valid callsign!"
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
async with self.session.get(base_url + callsign) as resp:
|
|
|
|
if resp.status != 200:
|
2020-01-27 00:37:52 -05:00
|
|
|
raise cmn.BotHTTPError(resp)
|
2020-01-08 17:47:34 -05:00
|
|
|
page = await resp.text()
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, features="html.parser")
|
|
|
|
tables = [[row for row in table.find_all("tr")] for table in soup.select("table.Database")]
|
|
|
|
|
|
|
|
table = tables[0]
|
|
|
|
|
|
|
|
# find the first table in the page, and use it to make a description
|
|
|
|
if len(table[0]) == 1:
|
|
|
|
for row in table:
|
|
|
|
desc += " ".join(row.getText().split())
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += "\n"
|
|
|
|
desc = desc.replace(callsign, f"`{callsign}`")
|
2020-01-08 17:47:34 -05:00
|
|
|
table = tables[1]
|
|
|
|
|
|
|
|
table_headers = table[0].find_all("th")
|
2020-01-30 06:15:42 -05:00
|
|
|
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
2020-01-08 17:47:34 -05:00
|
|
|
|
|
|
|
# catch if the wrong table was selected
|
2020-01-30 06:15:42 -05:00
|
|
|
if first_header is None or first_header != "Entity Name":
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.title = f"AE7Q History for {callsign}"
|
2019-12-23 17:54:20 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.url = base_url + callsign
|
|
|
|
embed.description = desc
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description += f"\nNo records found for `{callsign}`"
|
2019-12-23 17:54:20 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = await process_table(table[1:])
|
2020-01-07 04:28:51 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = f"AE7Q History for {callsign}"
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2020-01-07 04:28:51 -05:00
|
|
|
embed.url = base_url + callsign
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# add the first three rows of the table to the embed
|
|
|
|
for row in table[0:3]:
|
2020-01-30 06:15:42 -05:00
|
|
|
header = f"**{row[0]}** ({row[1]})" # **Name** (Applicant Type)
|
|
|
|
body = (f"Class: *{row[2]}*\n"
|
|
|
|
f"Region: *{row[3]}*\n"
|
|
|
|
f"Status: *{row[4]}*\n"
|
|
|
|
f"Granted: *{row[5]}*\n"
|
|
|
|
f"Effective: *{row[6]}*\n"
|
|
|
|
f"Cancelled: *{row[7]}*\n"
|
|
|
|
f"Expires: *{row[8]}*")
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.add_field(name=header, value=body, inline=False)
|
|
|
|
|
|
|
|
if len(table) > 3:
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
2019-10-08 18:57:37 -04:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.description = desc
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@_ae7q_lookup.command(name="trustee", aliases=["t"], category=cmn.Cats.LOOKUP)
|
2020-01-07 15:49:48 -05:00
|
|
|
async def _ae7q_trustee(self, ctx: commands.Context, callsign: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up the licenses for which a licensee is trustee on [ae7q.com](http://ae7q.com/)."""
|
2020-01-08 17:47:34 -05:00
|
|
|
with ctx.typing():
|
|
|
|
callsign = callsign.upper()
|
2020-01-30 06:15:42 -05:00
|
|
|
desc = ""
|
2020-01-08 17:47:34 -05:00
|
|
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
|
2021-01-29 23:43:30 -05:00
|
|
|
if not callsign.isalnum():
|
2021-01-29 22:55:26 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "AE7Q Trustee History for Callsign"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.description = "Not a valid callsign!"
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
async with self.session.get(base_url + callsign) as resp:
|
|
|
|
if resp.status != 200:
|
2020-01-27 00:37:52 -05:00
|
|
|
raise cmn.BotHTTPError(resp)
|
2020-01-08 17:47:34 -05:00
|
|
|
page = await resp.text()
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, features="html.parser")
|
|
|
|
tables = [[row for row in table.find_all("tr")] for table in soup.select("table.Database")]
|
|
|
|
|
|
|
|
try:
|
|
|
|
table = tables[2] if len(tables[0][0]) == 1 else tables[1]
|
|
|
|
except IndexError:
|
|
|
|
embed.title = f"AE7Q Trustee History for {callsign}"
|
2020-01-07 15:49:48 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.url = base_url + callsign
|
|
|
|
embed.description = desc
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description += f"\nNo records found for `{callsign}`"
|
2020-01-07 15:49:48 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table_headers = table[0].find_all("th")
|
2020-01-30 06:15:42 -05:00
|
|
|
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# catch if the wrong table was selected
|
|
|
|
if first_header is None or not first_header.startswith("With"):
|
|
|
|
embed.title = f"AE7Q Trustee History for {callsign}"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.url = base_url + callsign
|
|
|
|
embed.description = desc
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description += f"\nNo records found for `{callsign}`"
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = await process_table(table[2:])
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-07 15:49:48 -05:00
|
|
|
embed.title = f"AE7Q Trustee History for {callsign}"
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2020-01-07 15:49:48 -05:00
|
|
|
embed.url = base_url + callsign
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# add the first three rows of the table to the embed
|
|
|
|
for row in table[0:3]:
|
2020-01-30 06:15:42 -05:00
|
|
|
header = f"**{row[0]}** ({row[3]})" # **Name** (Applicant Type)
|
|
|
|
body = (f"Name: *{row[2]}*\n"
|
|
|
|
f"Region: *{row[1]}*\n"
|
|
|
|
f"Status: *{row[4]}*\n"
|
|
|
|
f"Granted: *{row[5]}*\n"
|
|
|
|
f"Effective: *{row[6]}*\n"
|
|
|
|
f"Cancelled: *{row[7]}*\n"
|
|
|
|
f"Expires: *{row[8]}*")
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.add_field(name=header, value=body, inline=False)
|
|
|
|
|
|
|
|
if len(table) > 3:
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.description = desc
|
2019-10-08 18:57:37 -04:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
2019-10-07 16:11:30 -04:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@_ae7q_lookup.command(name="applications", aliases=["a"], category=cmn.Cats.LOOKUP)
|
2020-01-07 15:49:48 -05:00
|
|
|
async def _ae7q_applications(self, ctx: commands.Context, callsign: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up the application history for a callsign on [ae7q.com](http://ae7q.com/)."""
|
2020-01-08 16:20:52 -05:00
|
|
|
"""
|
2020-01-08 17:47:34 -05:00
|
|
|
with ctx.typing():
|
|
|
|
callsign = callsign.upper()
|
2020-01-30 06:15:42 -05:00
|
|
|
desc = ""
|
2020-01-08 17:47:34 -05:00
|
|
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
|
2021-01-29 23:43:30 -05:00
|
|
|
if not callsign.isalnum():
|
2021-01-29 22:55:26 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "AE7Q Application History for Callsign"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.description = "Not a valid callsign!"
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
async with self.session.get(base_url + callsign) as resp:
|
|
|
|
if resp.status != 200:
|
2020-01-27 00:37:52 -05:00
|
|
|
raise cmn.BotHTTPError(resp)
|
2020-01-08 17:47:34 -05:00
|
|
|
page = await resp.text()
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, features="html.parser")
|
|
|
|
tables = [[row for row in table.find_all("tr")] for table in soup.select("table.Database")]
|
|
|
|
|
|
|
|
table = tables[0]
|
|
|
|
|
|
|
|
# find the first table in the page, and use it to make a description
|
|
|
|
if len(table[0]) == 1:
|
|
|
|
for row in table:
|
|
|
|
desc += " ".join(row.getText().split())
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += "\n"
|
|
|
|
desc = desc.replace(callsign, f"`{callsign}`")
|
2020-01-08 17:47:34 -05:00
|
|
|
|
|
|
|
# select the last table to get applications
|
|
|
|
table = tables[-1]
|
|
|
|
|
|
|
|
table_headers = table[0].find_all("th")
|
2020-01-30 06:15:42 -05:00
|
|
|
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
2020-01-08 17:47:34 -05:00
|
|
|
|
|
|
|
# catch if the wrong table was selected
|
|
|
|
if first_header is None or not first_header.startswith("Receipt"):
|
|
|
|
embed.title = f"AE7Q Application History for {callsign}"
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.url = base_url + callsign
|
|
|
|
embed.description = desc
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description += f"\nNo records found for `{callsign}`"
|
2020-01-08 16:20:52 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = await process_table(table[1:])
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.title = f"AE7Q Application History for {callsign}"
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.url = base_url + callsign
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# add the first three rows of the table to the embed
|
|
|
|
for row in table[0:3]:
|
2020-01-30 06:15:42 -05:00
|
|
|
header = f"**{row[1]}** ({row[3]})" # **Name** (Callsign)
|
|
|
|
body = (f"Received: *{row[0]}*\n"
|
|
|
|
f"Region: *{row[2]}*\n"
|
|
|
|
f"Purpose: *{row[5]}*\n"
|
|
|
|
f"Last Action: *{row[7]}*\n"
|
|
|
|
f"Application Status: *{row[8]}*\n")
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.add_field(name=header, value=body, inline=False)
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
if len(table) > 3:
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.description = desc
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
2020-01-08 16:20:52 -05:00
|
|
|
"""
|
2020-01-27 00:37:52 -05:00
|
|
|
raise NotImplementedError("Application history lookup not yet supported. "
|
|
|
|
"Check back in a later version of the bot.")
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@_ae7q_lookup.command(name="frn", aliases=["f"], category=cmn.Cats.LOOKUP)
|
2020-01-07 15:49:48 -05:00
|
|
|
async def _ae7q_frn(self, ctx: commands.Context, frn: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up the history of an FRN on [ae7q.com](http://ae7q.com/)."""
|
2020-01-07 15:49:48 -05:00
|
|
|
"""
|
|
|
|
NOTES:
|
|
|
|
- 2 tables: callsign history and application history
|
|
|
|
- If not found: no tables
|
|
|
|
"""
|
2020-01-08 17:47:34 -05:00
|
|
|
with ctx.typing():
|
|
|
|
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
|
2021-01-29 23:43:30 -05:00
|
|
|
if not frn.isdecimal():
|
2021-01-29 22:55:26 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "AE7Q History for FRN"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.description = "Not a valid FRN!"
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
async with self.session.get(base_url + frn) as resp:
|
|
|
|
if resp.status != 200:
|
2020-01-27 00:37:52 -05:00
|
|
|
raise cmn.BotHTTPError(resp)
|
2020-01-08 17:47:34 -05:00
|
|
|
page = await resp.text()
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, features="html.parser")
|
|
|
|
tables = [[row for row in table.find_all("tr")] for table in soup.select("table.Database")]
|
|
|
|
|
|
|
|
if not len(tables):
|
|
|
|
embed.title = f"AE7Q History for FRN {frn}"
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.url = base_url + frn
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"No records found for FRN `{frn}`"
|
2020-01-08 16:20:52 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = tables[0]
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table_headers = table[0].find_all("th")
|
2020-01-30 06:15:42 -05:00
|
|
|
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# catch if the wrong table was selected
|
2020-01-30 06:15:42 -05:00
|
|
|
if first_header is None or not first_header.startswith("With Licensee"):
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.title = f"AE7Q History for FRN {frn}"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.url = base_url + frn
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"No records found for FRN `{frn}`"
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = await process_table(table[2:])
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.title = f"AE7Q History for FRN {frn}"
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2020-01-08 16:20:52 -05:00
|
|
|
embed.url = base_url + frn
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# add the first three rows of the table to the embed
|
|
|
|
for row in table[0:3]:
|
2020-01-30 06:15:42 -05:00
|
|
|
header = f"**{row[0]}** ({row[3]})" # **Callsign** (Applicant Type)
|
|
|
|
body = (f"Name: *{row[2]}*\n"
|
|
|
|
f"Class: *{row[4]}*\n"
|
|
|
|
f"Region: *{row[1]}*\n"
|
|
|
|
f"Status: *{row[5]}*\n"
|
|
|
|
f"Granted: *{row[6]}*\n"
|
|
|
|
f"Effective: *{row[7]}*\n"
|
|
|
|
f"Cancelled: *{row[8]}*\n"
|
|
|
|
f"Expires: *{row[9]}*")
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.add_field(name=header, value=body, inline=False)
|
|
|
|
|
|
|
|
if len(table) > 3:
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"Records 1 to 3 of {len(table)}. See ae7q.com for more..."
|
2020-01-08 16:20:52 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
2020-01-07 15:49:48 -05:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@_ae7q_lookup.command(name="licensee", aliases=["l"], category=cmn.Cats.LOOKUP)
|
2020-01-08 17:07:02 -05:00
|
|
|
async def _ae7q_licensee(self, ctx: commands.Context, licensee_id: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Looks up the history of a licensee ID on [ae7q.com](http://ae7q.com/)."""
|
2020-01-08 17:47:34 -05:00
|
|
|
with ctx.typing():
|
|
|
|
licensee_id = licensee_id.upper()
|
|
|
|
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
|
2021-01-29 23:43:30 -05:00
|
|
|
if not licensee_id.isalnum():
|
2021-01-29 22:55:26 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "AE7Q History for Licensee"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.description = "Not a valid licensee ID!"
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
async with self.session.get(base_url + licensee_id) as resp:
|
|
|
|
if resp.status != 200:
|
2020-01-27 00:37:52 -05:00
|
|
|
raise cmn.BotHTTPError(resp)
|
2020-01-08 17:47:34 -05:00
|
|
|
page = await resp.text()
|
|
|
|
|
|
|
|
soup = BeautifulSoup(page, features="html.parser")
|
|
|
|
tables = [[row for row in table.find_all("tr")] for table in soup.select("table.Database")]
|
|
|
|
|
|
|
|
if not len(tables):
|
|
|
|
embed.title = f"AE7Q History for Licensee {licensee_id}"
|
2020-01-08 17:07:02 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.url = base_url + licensee_id
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"No records found for Licensee `{licensee_id}`"
|
2020-01-08 17:07:02 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = tables[0]
|
2020-01-08 17:07:02 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table_headers = table[0].find_all("th")
|
2020-01-30 06:15:42 -05:00
|
|
|
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
2020-01-08 17:07:02 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
# catch if the wrong table was selected
|
2020-01-30 06:15:42 -05:00
|
|
|
if first_header is None or not first_header.startswith("With FCC"):
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.title = f"AE7Q History for Licensee {licensee_id}"
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
embed.url = base_url + licensee_id
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"No records found for Licensee `{licensee_id}`"
|
2020-01-08 17:47:34 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
return
|
2020-01-08 17:07:02 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
table = await process_table(table[2:])
|
2020-01-08 17:07:02 -05:00
|
|
|
|
2020-01-08 17:47:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-08 17:07:02 -05:00
|
|
|
embed.title = f"AE7Q History for Licensee {licensee_id}"
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2020-01-08 17:07:02 -05:00
|
|
|
embed.url = base_url + licensee_id
|
2020-01-08 17:47:34 -05:00
|
|
|
|
|
|
|
# add the first three rows of the table to the embed
|
|
|
|
for row in table[0:3]:
|
2020-01-30 06:15:42 -05:00
|
|
|
header = f"**{row[0]}** ({row[3]})" # **Callsign** (Applicant Type)
|
|
|
|
body = (f"Name: *{row[2]}*\n"
|
|
|
|
f"Class: *{row[4]}*\n"
|
|
|
|
f"Region: *{row[1]}*\n"
|
|
|
|
f"Status: *{row[5]}*\n"
|
|
|
|
f"Granted: *{row[6]}*\n"
|
|
|
|
f"Effective: *{row[7]}*\n"
|
|
|
|
f"Cancelled: *{row[8]}*\n"
|
|
|
|
f"Expires: *{row[9]}*")
|
2020-01-08 17:47:34 -05:00
|
|
|
embed.add_field(name=header, value=body, inline=False)
|
|
|
|
|
|
|
|
if len(table) > 3:
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"Records 1 to 3 of {len(table)}. See ae7q.com for more..."
|
2020-01-08 17:47:34 -05:00
|
|
|
|
2020-01-08 17:07:02 -05:00
|
|
|
await ctx.send(embed=embed)
|
2019-10-07 16:11:30 -04:00
|
|
|
|
|
|
|
|
2020-01-07 04:28:51 -05:00
|
|
|
async def process_table(table: list):
|
2020-01-07 15:49:48 -05:00
|
|
|
"""Processes tables (*not* including headers) and returns the processed table"""
|
2020-01-07 04:28:51 -05:00
|
|
|
table_contents = []
|
2020-01-07 15:49:48 -05:00
|
|
|
for tr in table:
|
2020-01-07 04:28:51 -05:00
|
|
|
row = []
|
2020-01-30 06:15:42 -05:00
|
|
|
for td in tr.find_all("td"):
|
2020-01-07 04:28:51 -05:00
|
|
|
cell_val = td.getText().strip()
|
2020-01-30 06:15:42 -05:00
|
|
|
row.append(cell_val if cell_val else "-")
|
2020-01-07 04:28:51 -05:00
|
|
|
|
|
|
|
# take care of columns that span multiple rows by copying the contents rightward
|
2020-01-30 06:15:42 -05:00
|
|
|
if "colspan" in td.attrs and int(td.attrs["colspan"]) > 1:
|
|
|
|
for i in range(int(td.attrs["colspan"]) - 1):
|
2020-01-07 04:28:51 -05:00
|
|
|
row.append(row[-1])
|
|
|
|
|
|
|
|
# get rid of ditto marks by copying the contents from the previous row
|
|
|
|
for i, cell in enumerate(row):
|
|
|
|
if cell == "\"":
|
|
|
|
row[i] = table_contents[-1][i]
|
|
|
|
# add row to table
|
|
|
|
table_contents += [row]
|
|
|
|
return table_contents
|
|
|
|
|
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
def setup(bot: commands.Bot):
|
2019-10-07 16:11:30 -04:00
|
|
|
bot.add_cog(AE7QCog(bot))
|