mirror of
https://github.com/miaowware/qrm2.git
synced 2026-06-04 06:54:45 -04:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef6f01d1a3 | |||
| 91c5217d24 | |||
| 4659cf2a48 | |||
| d33dad9f89 | |||
| be083d2cc8 | |||
| e2d1d1fc87 | |||
| 68eaeff476 | |||
| f690ebb357 | |||
| 51e571b97d | |||
| 85ac05c337 | |||
| 718b2a7a80 | |||
| 0189db8792 | |||
| 80d6a989cc | |||
| 8f1782dcc0 |
@@ -0,0 +1,12 @@
|
|||||||
|
name: "Checks"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
changelog:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: dangoslen/changelog-enforcer@v2
|
||||||
@@ -27,7 +27,9 @@ jobs:
|
|||||||
- name: Build image
|
- name: Build image
|
||||||
id: build_image
|
id: build_image
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME=${GITHUB_REPOSITORY#*/}
|
IMAGE_ID=${GITHUB_REPOSITORY,,}
|
||||||
|
IMAGE_NAME=${IMAGE_ID#*/}
|
||||||
|
echo ::set-output name=image_id::$IMAGE_ID
|
||||||
echo ::set-output name=image_name::$IMAGE_NAME
|
echo ::set-output name=image_name::$IMAGE_NAME
|
||||||
docker build . --file Dockerfile -t $IMAGE_NAME
|
docker build . --file Dockerfile -t $IMAGE_NAME
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ jobs:
|
|||||||
id: tag_image
|
id: tag_image
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME=${{ steps.build_image.outputs.image_name }}
|
IMAGE_NAME=${{ steps.build_image.outputs.image_name }}
|
||||||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
|
IMAGE_ID=ghcr.io/${{ steps.build_image.outputs.image_id }}
|
||||||
echo IMAGE_ID=$IMAGE_ID
|
echo IMAGE_ID=$IMAGE_ID
|
||||||
echo ::set-output name=image_id::$IMAGE_ID
|
echo ::set-output name=image_id::$IMAGE_ID
|
||||||
|
|
||||||
@@ -62,8 +64,11 @@ jobs:
|
|||||||
|
|
||||||
- name: Push images to registry
|
- name: Push images to registry
|
||||||
run: |
|
run: |
|
||||||
[[ "${{ steps.tag_image.outputs.version }}" != "dev" ]] && docker push ${{ steps.tag_image.outputs.image_id }}:latest || true
|
VERSION=${{ steps.tag_image.outputs.version }}
|
||||||
docker push ${{ steps.tag_image.outputs.image_id }}:${{ steps.tag_image.outputs.version }}
|
IMAGE_ID=${{ steps.tag_image.outputs.image_id }}
|
||||||
|
|
||||||
|
[[ "$VERSION" != "dev" ]] && docker push $IMAGE_ID:latest || true
|
||||||
|
docker push $IMAGE_ID:$VERSION
|
||||||
|
|
||||||
- name: Deploy official images
|
- name: Deploy official images
|
||||||
id: deploy_images
|
id: deploy_images
|
||||||
|
|||||||
@@ -1,44 +1,22 @@
|
|||||||
name: Linting
|
name: Linting
|
||||||
|
|
||||||
on: [push,pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
precheck:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
outputs:
|
|
||||||
should_skip: ${{ steps.skip_check.outputs.should_skip }}
|
|
||||||
steps:
|
|
||||||
- id: skip_check
|
|
||||||
uses: fkirc/skip-duplicate-actions@master
|
|
||||||
with:
|
|
||||||
# skip concurrent jobs if they are on the same thing
|
|
||||||
concurrent_skipping: 'same_content'
|
|
||||||
# never skip PR + manual/scheduled runs
|
|
||||||
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
|
|
||||||
|
|
||||||
flake8:
|
flake8:
|
||||||
needs: precheck
|
runs-on: ubuntu-latest
|
||||||
if: ${{ needs.precheck.outputs.should_skip != 'true' }}
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
python-version: [3.9]
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@master
|
||||||
- name: Setup Python ${{ matrix.python-version }}
|
- name: Setup Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v1
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: "3.9"
|
||||||
architecture: x64
|
architecture: x64
|
||||||
- name: Install flake8
|
- name: Install flake8
|
||||||
run: pip install flake8
|
run: pip install flake8
|
||||||
- name: Run flake8
|
- name: Run flake8
|
||||||
uses: suo/flake8-github-action@releases/v1
|
run: flake8 --format='::error title=flake8,file=%(path)s,line=%(row)d,col=%(col)d::[%(code)s] %(text)s'
|
||||||
with:
|
|
||||||
checkName: 'flake8' # NOTE: this needs to be the same as the job name
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
|
|||||||
+19
-1
@@ -7,6 +7,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
|
||||||
|
## [2.8.0] - 2022-06-24
|
||||||
|
### Removed
|
||||||
|
- `?ae7q` command (#448).
|
||||||
|
|
||||||
|
|
||||||
|
## [2.7.6] - 2022-06-13
|
||||||
|
### Fixed
|
||||||
|
- Issue where `?muf` and `?fof2` would fail with an aiohttp error.
|
||||||
|
|
||||||
|
|
||||||
|
## [2.7.5] - 2022-06-08
|
||||||
|
### Changed
|
||||||
|
- Bumped ctyparser to 2.2.1.
|
||||||
|
|
||||||
|
|
||||||
## [2.7.4] - 2021-10-07
|
## [2.7.4] - 2021-10-07
|
||||||
### Added
|
### Added
|
||||||
- a new way to support qrm's development.
|
- a new way to support qrm's development.
|
||||||
@@ -214,7 +229,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
## 1.0.0 - 2019-07-31 [YANKED]
|
## 1.0.0 - 2019-07-31 [YANKED]
|
||||||
|
|
||||||
|
|
||||||
[Unreleased]: https://github.com/miaowware/qrm2/compare/v2.7.4...HEAD
|
[Unreleased]: https://github.com/miaowware/qrm2/compare/v2.8.0...HEAD
|
||||||
|
[2.8.0]: https://github.com/miaowware/qrm2/releases/tag/v2.8.0
|
||||||
|
[2.7.6]: https://github.com/miaowware/qrm2/releases/tag/v2.7.6
|
||||||
|
[2.7.5]: https://github.com/miaowware/qrm2/releases/tag/v2.7.5
|
||||||
[2.7.4]: https://github.com/miaowware/qrm2/releases/tag/v2.7.4
|
[2.7.4]: https://github.com/miaowware/qrm2/releases/tag/v2.7.4
|
||||||
[2.7.3]: https://github.com/miaowware/qrm2/releases/tag/v2.7.3
|
[2.7.3]: https://github.com/miaowware/qrm2/releases/tag/v2.7.3
|
||||||
[2.7.2]: https://github.com/miaowware/qrm2/releases/tag/v2.7.2
|
[2.7.2]: https://github.com/miaowware/qrm2/releases/tag/v2.7.2
|
||||||
|
|||||||
+12
-11
@@ -1,17 +1,19 @@
|
|||||||
FROM voidlinux/voidlinux
|
FROM ghcr.io/void-linux/void-linux:latest-mini-x86_64
|
||||||
|
LABEL org.opencontainers.image.source https://github.com/miaowware/qrm2
|
||||||
|
|
||||||
COPY . /app
|
COPY . /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ENV PYTHON_BIN python3
|
ARG REPOSITORY=https://repo-us.voidlinux.org/current
|
||||||
|
ARG PKGS="cairo libjpeg-turbo"
|
||||||
|
ARG UID 1000
|
||||||
|
ARG GID 1000
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
echo "**** update packages ****" && \
|
echo "**** update system ****" && \
|
||||||
xbps-install -Suy && \
|
xbps-install -SuyM -R ${REPOSITORY} && \
|
||||||
echo "**** install system packages ****" && \
|
echo "**** install system packages ****" && \
|
||||||
export runtime_deps='cairo libjpeg-turbo' && \
|
xbps-install -yM -R ${REPOSITORY} ${PKGS} python3 python3-pip && \
|
||||||
export runtime_pkgs="${runtime_deps} python3-pip python3" && \
|
|
||||||
xbps-install -y $runtime_pkgs && \
|
|
||||||
echo "**** install pip packages ****" && \
|
echo "**** install pip packages ****" && \
|
||||||
pip3 install -U pip setuptools wheel && \
|
pip3 install -U pip setuptools wheel && \
|
||||||
pip3 install -r requirements.txt && \
|
pip3 install -r requirements.txt && \
|
||||||
@@ -21,10 +23,9 @@ RUN \
|
|||||||
/tmp/* \
|
/tmp/* \
|
||||||
/var/cache/xbps/*
|
/var/cache/xbps/*
|
||||||
|
|
||||||
ARG UID
|
ENV PYTHON_BIN python3
|
||||||
ENV UID=${UID:-1000}
|
ENV PYTHONUNBUFFERED 1
|
||||||
ARG GID
|
|
||||||
ENV GID=${GID:-1000}
|
|
||||||
USER $UID:$GID
|
USER $UID:$GID
|
||||||
|
|
||||||
CMD ["/bin/sh", "run.sh", "--pass-errors", "--no-botenv"]
|
CMD ["/bin/sh", "run.sh", "--pass-errors", "--no-botenv"]
|
||||||
|
|||||||
+2
-7
@@ -23,14 +23,11 @@ This is the easiest method for running the bot without any modifications.
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
qrm2:
|
qrm2:
|
||||||
image: "docker.pkg.github.com/miaowware/qrm2/qrm2:latest"
|
image: "ghcr.io/miaowware/qrm2:latest"
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
volumes:
|
volumes:
|
||||||
- "./data:/app/data:rw"
|
- "./data:/app/data:rw"
|
||||||
environment:
|
|
||||||
- PYTHONUNBUFFERED=1
|
|
||||||
```
|
```
|
||||||
*Note that Github's registry requires [a few extra steps](https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages) during the initial setup.*
|
|
||||||
|
|
||||||
3. Create a subdirectory named `data`.
|
3. Create a subdirectory named `data`.
|
||||||
|
|
||||||
@@ -64,8 +61,6 @@ This is the easiest method to run the bot with modifications.
|
|||||||
restart: on-failure
|
restart: on-failure
|
||||||
volumes:
|
volumes:
|
||||||
- "./data:/app/data:rw"
|
- "./data:/app/data:rw"
|
||||||
environment:
|
|
||||||
- PYTHONUNBUFFERED=1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Create a subdirectory named `data`.
|
3. Create a subdirectory named `data`.
|
||||||
@@ -112,4 +107,4 @@ This methods is not very nice to use.
|
|||||||
|
|
||||||
Where `[image]` is either of:
|
Where `[image]` is either of:
|
||||||
- `qrm2:local-latest` if you are building your own.
|
- `qrm2:local-latest` if you are building your own.
|
||||||
- `docker.pkg.github.com/miaowware/qrm2/qrm2:latest` if you want to use the prebuilt image.
|
- `ghcr.io/miaowware/qrm2:latest` if you want to use the prebuilt image.
|
||||||
|
|||||||
+11
-418
@@ -7,429 +7,22 @@ SPDX-License-Identifier: LiLiQ-Rplus-1.1
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
import aiohttp
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
import discord.ext.commands as commands
|
import discord.ext.commands as commands
|
||||||
|
|
||||||
import common as cmn
|
from common import embed_factory, colours
|
||||||
|
|
||||||
|
|
||||||
class AE7QCog(commands.Cog):
|
class AE7QCog(commands.Cog):
|
||||||
def __init__(self, bot: commands.Bot):
|
@commands.command(name="ae7q", aliases=["ae"], case_insensitive=True)
|
||||||
self.bot = bot
|
async def _ae7q_lookup(self, ctx: commands.Context, *, _):
|
||||||
self.session = aiohttp.ClientSession(connector=bot.qrm.connector)
|
"""Removed in v2.8.0"""
|
||||||
|
embed = embed_factory(ctx)
|
||||||
@commands.group(name="ae7q", aliases=["ae"], case_insensitive=True, category=cmn.Cats.LOOKUP)
|
embed.colour = colours.bad
|
||||||
async def _ae7q_lookup(self, ctx: commands.Context):
|
embed.title = "Command removed"
|
||||||
"""Looks up a callsign, FRN, or Licensee ID on [ae7q.com](http://ae7q.com/)."""
|
embed.description = ("This command was removed in v2.8.0.\n"
|
||||||
if ctx.invoked_subcommand is None:
|
"For context, see [this Github issue](https://github.com/miaowware/qrm2/issues/448)")
|
||||||
await ctx.send_help(ctx.command)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="call", aliases=["c"], category=cmn.Cats.LOOKUP)
|
|
||||||
async def _ae7q_call(self, ctx: commands.Context, callsign: str):
|
|
||||||
"""Looks up the history of a callsign on [ae7q.com](http://ae7q.com/)."""
|
|
||||||
with ctx.typing():
|
|
||||||
callsign = callsign.upper()
|
|
||||||
desc = ""
|
|
||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
|
|
||||||
if not callsign.isalnum():
|
|
||||||
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
|
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
|
||||||
if resp.status != 200:
|
|
||||||
raise cmn.BotHTTPError(resp)
|
|
||||||
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())
|
|
||||||
desc += "\n"
|
|
||||||
desc = desc.replace(callsign, f"`{callsign}`")
|
|
||||||
table = tables[1]
|
|
||||||
|
|
||||||
table_headers = table[0].find_all("th")
|
|
||||||
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
|
||||||
|
|
||||||
# catch if the wrong table was selected
|
|
||||||
if first_header is None or first_header != "Entity Name":
|
|
||||||
embed.title = f"AE7Q History for {callsign}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
embed.description = desc
|
|
||||||
embed.description += f"\nNo records found for `{callsign}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = await process_table(table[1:])
|
|
||||||
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
embed.title = f"AE7Q History for {callsign}"
|
|
||||||
embed.colour = cmn.colours.good
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
|
|
||||||
# add the first three rows of the table to the embed
|
|
||||||
for row in table[0:3]:
|
|
||||||
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]}*")
|
|
||||||
embed.add_field(name=header, value=body, inline=False)
|
|
||||||
|
|
||||||
if len(table) > 3:
|
|
||||||
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
|
||||||
|
|
||||||
embed.description = desc
|
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="trustee", aliases=["t"], category=cmn.Cats.LOOKUP)
|
|
||||||
async def _ae7q_trustee(self, ctx: commands.Context, callsign: str):
|
|
||||||
"""Looks up the licenses for which a licensee is trustee on [ae7q.com](http://ae7q.com/)."""
|
|
||||||
with ctx.typing():
|
|
||||||
callsign = callsign.upper()
|
|
||||||
desc = ""
|
|
||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
|
|
||||||
if not callsign.isalnum():
|
|
||||||
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
|
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
|
||||||
if resp.status != 200:
|
|
||||||
raise cmn.BotHTTPError(resp)
|
|
||||||
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}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
embed.description = desc
|
|
||||||
embed.description += f"\nNo records found for `{callsign}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table_headers = table[0].find_all("th")
|
|
||||||
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
|
||||||
|
|
||||||
# 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
|
|
||||||
embed.description += f"\nNo records found for `{callsign}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = await process_table(table[2:])
|
|
||||||
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
embed.title = f"AE7Q Trustee History for {callsign}"
|
|
||||||
embed.colour = cmn.colours.good
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
|
|
||||||
# add the first three rows of the table to the embed
|
|
||||||
for row in table[0:3]:
|
|
||||||
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]}*")
|
|
||||||
embed.add_field(name=header, value=body, inline=False)
|
|
||||||
|
|
||||||
if len(table) > 3:
|
|
||||||
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
|
||||||
|
|
||||||
embed.description = desc
|
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="applications", aliases=["a"], category=cmn.Cats.LOOKUP)
|
|
||||||
async def _ae7q_applications(self, ctx: commands.Context, callsign: str):
|
|
||||||
"""Looks up the application history for a callsign on [ae7q.com](http://ae7q.com/)."""
|
|
||||||
"""
|
|
||||||
with ctx.typing():
|
|
||||||
callsign = callsign.upper()
|
|
||||||
desc = ""
|
|
||||||
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
|
|
||||||
if not callsign.isalnum():
|
|
||||||
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
|
|
||||||
|
|
||||||
async with self.session.get(base_url + callsign) as resp:
|
|
||||||
if resp.status != 200:
|
|
||||||
raise cmn.BotHTTPError(resp)
|
|
||||||
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())
|
|
||||||
desc += "\n"
|
|
||||||
desc = desc.replace(callsign, f"`{callsign}`")
|
|
||||||
|
|
||||||
# select the last table to get applications
|
|
||||||
table = tables[-1]
|
|
||||||
|
|
||||||
table_headers = table[0].find_all("th")
|
|
||||||
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
|
||||||
|
|
||||||
# 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}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
embed.description = desc
|
|
||||||
embed.description += f"\nNo records found for `{callsign}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = await process_table(table[1:])
|
|
||||||
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
embed.title = f"AE7Q Application History for {callsign}"
|
|
||||||
embed.colour = cmn.colours.good
|
|
||||||
embed.url = base_url + callsign
|
|
||||||
|
|
||||||
# add the first three rows of the table to the embed
|
|
||||||
for row in table[0:3]:
|
|
||||||
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")
|
|
||||||
embed.add_field(name=header, value=body, inline=False)
|
|
||||||
|
|
||||||
if len(table) > 3:
|
|
||||||
desc += f"\nRecords 1 to 3 of {len(table)}. See ae7q.com for more..."
|
|
||||||
|
|
||||||
embed.description = desc
|
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
"""
|
|
||||||
raise NotImplementedError("Application history lookup not yet supported. "
|
|
||||||
"Check back in a later version of the bot.")
|
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="frn", aliases=["f"], category=cmn.Cats.LOOKUP)
|
|
||||||
async def _ae7q_frn(self, ctx: commands.Context, frn: str):
|
|
||||||
"""Looks up the history of an FRN on [ae7q.com](http://ae7q.com/)."""
|
|
||||||
"""
|
|
||||||
NOTES:
|
|
||||||
- 2 tables: callsign history and application history
|
|
||||||
- If not found: no tables
|
|
||||||
"""
|
|
||||||
with ctx.typing():
|
|
||||||
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
|
|
||||||
if not frn.isdecimal():
|
|
||||||
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
|
|
||||||
|
|
||||||
async with self.session.get(base_url + frn) as resp:
|
|
||||||
if resp.status != 200:
|
|
||||||
raise cmn.BotHTTPError(resp)
|
|
||||||
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}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + frn
|
|
||||||
embed.description = f"No records found for FRN `{frn}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = tables[0]
|
|
||||||
|
|
||||||
table_headers = table[0].find_all("th")
|
|
||||||
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
|
||||||
|
|
||||||
# catch if the wrong table was selected
|
|
||||||
if first_header is None or not first_header.startswith("With Licensee"):
|
|
||||||
embed.title = f"AE7Q History for FRN {frn}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + frn
|
|
||||||
embed.description = f"No records found for FRN `{frn}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = await process_table(table[2:])
|
|
||||||
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
embed.title = f"AE7Q History for FRN {frn}"
|
|
||||||
embed.colour = cmn.colours.good
|
|
||||||
embed.url = base_url + frn
|
|
||||||
|
|
||||||
# add the first three rows of the table to the embed
|
|
||||||
for row in table[0:3]:
|
|
||||||
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]}*")
|
|
||||||
embed.add_field(name=header, value=body, inline=False)
|
|
||||||
|
|
||||||
if len(table) > 3:
|
|
||||||
embed.description = f"Records 1 to 3 of {len(table)}. See ae7q.com for more..."
|
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
@_ae7q_lookup.command(name="licensee", aliases=["l"], category=cmn.Cats.LOOKUP)
|
|
||||||
async def _ae7q_licensee(self, ctx: commands.Context, licensee_id: str):
|
|
||||||
"""Looks up the history of a licensee ID on [ae7q.com](http://ae7q.com/)."""
|
|
||||||
with ctx.typing():
|
|
||||||
licensee_id = licensee_id.upper()
|
|
||||||
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
|
|
||||||
if not licensee_id.isalnum():
|
|
||||||
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
|
|
||||||
|
|
||||||
async with self.session.get(base_url + licensee_id) as resp:
|
|
||||||
if resp.status != 200:
|
|
||||||
raise cmn.BotHTTPError(resp)
|
|
||||||
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}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + licensee_id
|
|
||||||
embed.description = f"No records found for Licensee `{licensee_id}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = tables[0]
|
|
||||||
|
|
||||||
table_headers = table[0].find_all("th")
|
|
||||||
first_header = "".join(table_headers[0].strings) if len(table_headers) > 0 else None
|
|
||||||
|
|
||||||
# catch if the wrong table was selected
|
|
||||||
if first_header is None or not first_header.startswith("With FCC"):
|
|
||||||
embed.title = f"AE7Q History for Licensee {licensee_id}"
|
|
||||||
embed.colour = cmn.colours.bad
|
|
||||||
embed.url = base_url + licensee_id
|
|
||||||
embed.description = f"No records found for Licensee `{licensee_id}`"
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
return
|
|
||||||
|
|
||||||
table = await process_table(table[2:])
|
|
||||||
|
|
||||||
embed = cmn.embed_factory(ctx)
|
|
||||||
embed.title = f"AE7Q History for Licensee {licensee_id}"
|
|
||||||
embed.colour = cmn.colours.good
|
|
||||||
embed.url = base_url + licensee_id
|
|
||||||
|
|
||||||
# add the first three rows of the table to the embed
|
|
||||||
for row in table[0:3]:
|
|
||||||
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]}*")
|
|
||||||
embed.add_field(name=header, value=body, inline=False)
|
|
||||||
|
|
||||||
if len(table) > 3:
|
|
||||||
embed.description = f"Records 1 to 3 of {len(table)}. See ae7q.com for more..."
|
|
||||||
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
|
|
||||||
|
|
||||||
async def process_table(table: list):
|
|
||||||
"""Processes tables (*not* including headers) and returns the processed table"""
|
|
||||||
table_contents = []
|
|
||||||
for tr in table:
|
|
||||||
row = []
|
|
||||||
for td in tr.find_all("td"):
|
|
||||||
cell_val = td.getText().strip()
|
|
||||||
row.append(cell_val if cell_val else "-")
|
|
||||||
|
|
||||||
# take care of columns that span multiple rows by copying the contents rightward
|
|
||||||
if "colspan" in td.attrs and int(td.attrs["colspan"]) > 1:
|
|
||||||
for i in range(int(td.attrs["colspan"]) - 1):
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
bot.add_cog(AE7QCog(bot))
|
bot.add_cog(AE7QCog())
|
||||||
|
|||||||
+2
-2
@@ -33,7 +33,7 @@ class PropagationCog(commands.Cog):
|
|||||||
async def mufmap(self, ctx: commands.Context):
|
async def mufmap(self, ctx: commands.Context):
|
||||||
"""Shows a world map of the Maximum Usable Frequency (MUF)."""
|
"""Shows a world map of the Maximum Usable Frequency (MUF)."""
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
async with self.session.get(self.muf_url) as r:
|
async with self.session.get(self.muf_url, headers={"Connection": "Upgrade", "Upgrade": "http/1.1"}) as r:
|
||||||
svg = await r.read()
|
svg = await r.read()
|
||||||
out = BytesIO(cairosvg.svg2png(bytestring=svg))
|
out = BytesIO(cairosvg.svg2png(bytestring=svg))
|
||||||
file = discord.File(out, "muf_map.png")
|
file = discord.File(out, "muf_map.png")
|
||||||
@@ -47,7 +47,7 @@ class PropagationCog(commands.Cog):
|
|||||||
async def fof2map(self, ctx: commands.Context):
|
async def fof2map(self, ctx: commands.Context):
|
||||||
"""Shows a world map of the Critical Frequency (foF2)."""
|
"""Shows a world map of the Critical Frequency (foF2)."""
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
async with self.session.get(self.fof2_url) as r:
|
async with self.session.get(self.fof2_url, headers={"Connection": "Upgrade", "Upgrade": "http/1.1"}) as r:
|
||||||
svg = await r.read()
|
svg = await r.read()
|
||||||
out = BytesIO(cairosvg.svg2png(bytestring=svg))
|
out = BytesIO(cairosvg.svg2png(bytestring=svg))
|
||||||
file = discord.File(out, "fof2_map.png")
|
file = discord.File(out, "fof2_map.png")
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ contributing = """Check out the [source on GitHub](https://github.com/miaowware/
|
|||||||
|
|
||||||
All issues and requests related to resources (including maps, band charts, data) should be added \
|
All issues and requests related to resources (including maps, band charts, data) should be added \
|
||||||
in [miaowware/qrm-resources](https://github.com/miaowware/qrm-resources)."""
|
in [miaowware/qrm-resources](https://github.com/miaowware/qrm-resources)."""
|
||||||
release = "2.7.4"
|
release = "2.8.0"
|
||||||
bot_server = "https://discord.gg/Ntbg3J4"
|
bot_server = "https://discord.gg/Ntbg3J4"
|
||||||
|
|||||||
Reference in New Issue
Block a user