mirror of
https://github.com/miaowware/qrm2.git
synced 2025-08-04 06:12:26 -04:00
more work on ae7q callsign lookup
This commit is contained in:
parent
19284ee1cc
commit
d8d0b68100
@ -5,6 +5,12 @@ Copyright (C) 2019 Abigail Gold, 0x5c
|
|||||||
|
|
||||||
This file is part of discord-qrmbot and is released under the terms of the GNU
|
This file is part of discord-qrmbot and is released under the terms of the GNU
|
||||||
General Public License, version 2.
|
General Public License, version 2.
|
||||||
|
---
|
||||||
|
Test callsigns:
|
||||||
|
KN8U: active, restricted
|
||||||
|
AB2EE: expired, restricted
|
||||||
|
KE8FGB: assigned once, no restrictions
|
||||||
|
NA2AAA: unassigned, no records
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
@ -30,6 +36,7 @@ class AE7QCog(commands.Cog):
|
|||||||
@_ae7q_lookup.command(name="call")
|
@_ae7q_lookup.command(name="call")
|
||||||
async def _ae7q_call(self, ctx, callsign: str):
|
async def _ae7q_call(self, ctx, callsign: str):
|
||||||
callsign = callsign.upper()
|
callsign = callsign.upper()
|
||||||
|
desc = ''
|
||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
@ -39,9 +46,31 @@ class AE7QCog(commands.Cog):
|
|||||||
page = await resp.text()
|
page = await resp.text()
|
||||||
|
|
||||||
soup = BeautifulSoup(page, features="html.parser")
|
soup = BeautifulSoup(page, features="html.parser")
|
||||||
table = soup.select("table.Database")[1]
|
tables = soup.select("table.Database")
|
||||||
|
|
||||||
|
for table in tables:
|
||||||
|
rows = table.find_all("tr")
|
||||||
|
if len(rows) > 1 and len(rows[0]) > 1:
|
||||||
|
break
|
||||||
|
elif desc == '':
|
||||||
|
for row in rows:
|
||||||
|
desc += " ".join(row.getText().split())
|
||||||
|
desc += '\n'
|
||||||
|
desc = desc.replace(callsign, f'`{callsign}`')
|
||||||
|
rows = None
|
||||||
|
|
||||||
|
if rows is None:
|
||||||
|
embed = discord.Embed(title=f"AE7Q History for {callsign}",
|
||||||
|
colour=self.gs.colours.bad,
|
||||||
|
url=f"{base_url}{callsign}",
|
||||||
|
timestamp=datetime.utcnow())
|
||||||
|
embed.set_footer(text=ctx.author.name,
|
||||||
|
icon_url=str(ctx.author.avatar_url))
|
||||||
|
embed.description = desc
|
||||||
|
embed.description += f'\nNo records found for `{callsign}`'
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
|
||||||
rows = table.find_all("tr")
|
|
||||||
table_contents = [] # store your table here
|
table_contents = [] # store your table here
|
||||||
for tr in rows:
|
for tr in rows:
|
||||||
if rows.index(tr) == 0:
|
if rows.index(tr) == 0:
|
||||||
@ -62,35 +91,50 @@ class AE7QCog(commands.Cog):
|
|||||||
if len(row_cells) > 1:
|
if len(row_cells) > 1:
|
||||||
table_contents += [row_cells]
|
table_contents += [row_cells]
|
||||||
|
|
||||||
embed = discord.Embed(title=f"AE7Q History for {callsign}",
|
embed = discord.Embed(title=f"AE7Q Records for {callsign}",
|
||||||
colour=self.gs.colours.good,
|
colour=self.gs.colours.good,
|
||||||
url=f"{base_url}{callsign}",
|
url=f"{base_url}{callsign}",
|
||||||
timestamp=datetime.utcnow())
|
timestamp=datetime.utcnow())
|
||||||
|
|
||||||
embed.set_author(name=ctx.author.name,
|
embed.set_footer(text=ctx.author.name,
|
||||||
icon_url=str(ctx.author.avatar_url))
|
icon_url=str(ctx.author.avatar_url))
|
||||||
|
|
||||||
for row in table_contents:
|
for row in table_contents[0:3]:
|
||||||
embed.add_field(name=row[0], value=row[1], inline=False)
|
header = f'**{row[0]}** ({row[1]})'
|
||||||
embed.add_field(name="Class", value=row[2], inline=True)
|
body = f'Class: *{row[2]}*\n'
|
||||||
embed.add_field(name="Region", value=row[3], inline=True)
|
body += f'Region: *{row[3]}*\n'
|
||||||
embed.add_field(name="Status", value=row[4], inline=True)
|
body += f'Status: *{row[4]}*\n'
|
||||||
embed.add_field(name="Grant", value=row[5], inline=True)
|
body += f'Granted: *{row[5]}*\n'
|
||||||
embed.add_field(name="Effective", value=row[6], inline=True)
|
body += f'Effective: *{row[6]}*\n'
|
||||||
embed.add_field(name="Cancel", value=row[7], inline=True)
|
body += f'Cancelled: *{row[7]}*\n'
|
||||||
embed.add_field(name="Expire", value=row[8], inline=True)
|
body += f'Expires: *{row[8]}*'
|
||||||
|
embed.add_field(name=header, value=body, inline=False)
|
||||||
|
|
||||||
|
embed.description = desc
|
||||||
|
if len(table_contents) > 3:
|
||||||
|
embed.description += f'\nRecords 1 to 3 of {len(table_contents)}.'
|
||||||
|
embed.description += ' See ae7q.com for more...'
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="frn")
|
# TODO: write commands for other AE7Q response types?
|
||||||
async def _ae7q_frn(self, ctx, frn: str):
|
# @_ae7q_lookup.command(name="trustee")
|
||||||
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
# async def _ae7q_trustee(self, ctx, callsign: str):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="licensee", aliases=["lic"])
|
# @_ae7q_lookup.command(name="applications", aliases=['apps'])
|
||||||
async def _ae7q_licensee(self, ctx, frn: str):
|
# async def _ae7q_applications(self, ctx, callsign: str):
|
||||||
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
# pass
|
||||||
pass
|
|
||||||
|
# @_ae7q_lookup.command(name="frn")
|
||||||
|
# async def _ae7q_frn(self, ctx, frn: str):
|
||||||
|
# base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
||||||
|
# pass
|
||||||
|
|
||||||
|
# @_ae7q_lookup.command(name="licensee", aliases=["lic"])
|
||||||
|
# async def _ae7q_licensee(self, ctx, frn: str):
|
||||||
|
# base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
||||||
|
# pass
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user