From 4368e0b60338b961c77d39c1351f7744c70cecda Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 24 Dec 2019 23:11:43 -0500 Subject: [PATCH 1/5] correct some line continuations Fixes #43 --- exts/base.py | 3 +-- exts/lookup.py | 12 ++++-------- exts/qrz.py | 15 +++++---------- exts/study.py | 3 +-- 4 files changed, 11 insertions(+), 22 deletions(-) diff --git a/exts/base.py b/exts/base.py index b629bba..51ba2f7 100644 --- a/exts/base.py +++ b/exts/base.py @@ -141,8 +141,7 @@ class BaseCog(commands.Cog): @commands.command(name="echo", aliases=["e"], hidden=True) @commands.check(cmn.check_if_owner) async def _echo(self, ctx: commands.Context, channel: commands.TextChannelConverter, *, msg: str): - """Send a message in a channel as qrm. Only works within a server or DM to server, - not between servers.""" + """Send a message in a channel as qrm. Only works within a server or DM to server, not between servers.""" await channel.send(msg) diff --git a/exts/lookup.py b/exts/lookup.py index 6e88f71..fbeef80 100644 --- a/exts/lookup.py +++ b/exts/lookup.py @@ -48,14 +48,10 @@ class LookupCog(commands.Cog): while query: if query in self.cty.keys(): data = self.cty[query] - embed.add_field(name="Entity", - value=data['entity'])\ - .add_field(name="CQ Zone", - value=data['cq'])\ - .add_field(name="ITU Zone", - value=data['itu'])\ - .add_field(name="Continent", - value=data['continent'])\ + embed.add_field(name="Entity", value=data['entity'])\ + .add_field(name="CQ Zone", value=data['cq'])\ + .add_field(name="ITU Zone", value=data['itu'])\ + .add_field(name="Continent", value=data['continent'])\ .add_field(name="Time Zone", value=f'+{data["tz"]}' if data['tz'] > 0 else str(data['tz'])) embed.title += query diff --git a/exts/qrz.py b/exts/qrz.py index 27831a1..825e60e 100644 --- a/exts/qrz.py +++ b/exts/qrz.py @@ -42,8 +42,7 @@ class QRZCog(commands.Cog): raise ConnectionError(f'Unable to connect to QRZ (HTTP Error {resp.status})') resp_xml = etree.parse(BytesIO(await resp.read())).getroot() - resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', - namespaces={'x': 'http://xmldata.qrz.com'}) + resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', namespaces={'x': 'http://xmldata.qrz.com'}) resp_session = {el.tag.split('}')[1]: el.text for el in resp_xml_session[0].getiterator()} if 'Error' in resp_session: if 'Session Timeout' in resp_session['Error']: @@ -59,8 +58,7 @@ class QRZCog(commands.Cog): return raise ValueError(resp_session['Error']) - resp_xml_data = resp_xml.xpath('/x:QRZDatabase/x:Callsign', - namespaces={'x': 'http://xmldata.qrz.com'}) + resp_xml_data = resp_xml.xpath('/x:QRZDatabase/x:Callsign', namespaces={'x': 'http://xmldata.qrz.com'}) resp_data = {el.tag.split('}')[1]: el.text for el in resp_xml_data[0].getiterator()} embed = cmn.embed_factory(ctx) @@ -101,8 +99,7 @@ async def qrz_login(user: str, passwd: str, session: aiohttp.ClientSession): raise ConnectionError(f'Unable to connect to QRZ (HTTP Error {resp.status})') resp_xml = etree.parse(BytesIO(await resp.read())).getroot() - resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', - namespaces={'x': 'http://xmldata.qrz.com'}) + resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', namespaces={'x': 'http://xmldata.qrz.com'}) resp_session = {el.tag.split('}')[1]: el.text for el in resp_xml_session[0].getiterator()} if 'Error' in resp_session: raise ConnectionError(resp_session['Error']) @@ -118,8 +115,7 @@ async def qrz_test_session(key: str, session: aiohttp.ClientSession): raise ConnectionError(f'Unable to connect to QRZ (HTTP Error {resp.status})') resp_xml = etree.parse(BytesIO(await resp.read())).getroot() - resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', - namespaces={'x': 'http://xmldata.qrz.com'}) + resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', namespaces={'x': 'http://xmldata.qrz.com'}) resp_session = {el.tag.split('}')[1]: el.text for el in resp_xml_session[0].getiterator()} if 'Error' in resp_session: raise ConnectionError(resp_session['Error']) @@ -174,8 +170,7 @@ def qrz_process_info(data: dict): ('CQ Zone', data.get('cqzone', None)), ('ITU Zone', data.get('ituzone', None)), ('IOTA Designator', data.get('iota', None)), - ('Born', data.get('born', None)), - ]) + ('Born', data.get('born', None))]) def setup(bot): diff --git a/exts/study.py b/exts/study.py index 6c98fb4..fb8298e 100644 --- a/exts/study.py +++ b/exts/study.py @@ -78,8 +78,7 @@ class StudyCog(commands.Cog): embed.add_field(name='Answers:', value='**A:** ' + question['answers']['A'] + '\n**B:** ' + question['answers']['B'] + '\n**C:** ' + question['answers']['C'] + - '\n**D:** ' + question['answers']['D'], - inline=False) + '\n**D:** ' + question['answers']['D'], inline=False) embed.add_field(name='Answer:', value='Type _?rqa_ for answer', inline=False) if 'image' in question: image_url = f'https://hamstudy.org/_1330011/images/{selected_pool.split("_",1)[1]}/{question["image"]}' From 69d36fea7fc65a509b980523ff8aa85ced88c5c3 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 25 Dec 2019 02:30:03 -0500 Subject: [PATCH 2/5] oop --- exts/lookup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exts/lookup.py b/exts/lookup.py index fbeef80..b078bd9 100644 --- a/exts/lookup.py +++ b/exts/lookup.py @@ -48,11 +48,11 @@ class LookupCog(commands.Cog): while query: if query in self.cty.keys(): data = self.cty[query] - embed.add_field(name="Entity", value=data['entity'])\ - .add_field(name="CQ Zone", value=data['cq'])\ - .add_field(name="ITU Zone", value=data['itu'])\ - .add_field(name="Continent", value=data['continent'])\ - .add_field(name="Time Zone", + embed.add_field(name="Entity", value=data['entity']) + embed.add_field(name="CQ Zone", value=data['cq']) + embed.add_field(name="ITU Zone", value=data['itu']) + embed.add_field(name="Continent", value=data['continent']) + embed.add_field(name="Time Zone", value=f'+{data["tz"]}' if data['tz'] > 0 else str(data['tz'])) embed.title += query embed.colour = cmn.colours.good From b0072f779e5719327e9b63f6ae21e56b53700749 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 25 Dec 2019 02:48:59 -0500 Subject: [PATCH 3/5] addressing the issue for once --- exts/ae7q.py | 17 ++++++++--------- exts/base.py | 3 +-- exts/grid.py | 12 ++++++------ exts/qrz.py | 3 +-- exts/study.py | 8 ++++---- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/exts/ae7q.py b/exts/ae7q.py index e27a019..43a6981 100644 --- a/exts/ae7q.py +++ b/exts/ae7q.py @@ -97,19 +97,18 @@ class AE7QCog(commands.Cog): for row in table_contents[0:3]: header = f'**{row[0]}** ({row[1]})' - body = f'Class: *{row[2]}*\n' - body += f'Region: *{row[3]}*\n' - body += f'Status: *{row[4]}*\n' - body += f'Granted: *{row[5]}*\n' - body += f'Effective: *{row[6]}*\n' - body += f'Cancelled: *{row[7]}*\n' - body += f'Expires: *{row[8]}*' + 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) 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...' + embed.description += f'\nRecords 1 to 3 of {len(table_contents)}. See ae7q.com for more...' await ctx.send(embed=embed) diff --git a/exts/base.py b/exts/base.py index 51ba2f7..08d2b2c 100644 --- a/exts/base.py +++ b/exts/base.py @@ -22,8 +22,7 @@ import common as cmn class QrmHelpCommand(commands.HelpCommand): def __init__(self): - super().__init__(command_attrs={'help': 'Shows help about qrm or a command', - 'aliases': ['h']}) + super().__init__(command_attrs={'help': 'Shows help about qrm or a command', 'aliases': ['h']}) def get_bot_mapping(self): bot = self.context.bot diff --git a/exts/grid.py b/exts/grid.py index 570b2e9..2f2d41b 100644 --- a/exts/grid.py +++ b/exts/grid.py @@ -83,18 +83,18 @@ If two grid squares are given, the distance and azimuth between them is calculat # Haversine formula d_lat = math.radians(loc2[0] - loc[0]) d_lon = math.radians(loc2[1] - loc[1]) - a = math.sin(d_lat/2) ** 2 +\ - math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) *\ - math.sin(d_lon/2) ** 2 + a = math.sin(d_lat/2) ** 2 + + math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) + * math.sin(d_lon/2) ** 2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) d = radius * c d_mi = 0.6213712 * d # Bearing y_dist = math.sin(math.radians(loc2[1]-loc[1])) * math.cos(math.radians(loc2[0])) - x_dist = math.cos(math.radians(loc[0])) * math.sin(math.radians(loc2[0])) -\ - math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) *\ - math.cos(math.radians(loc2[1] - loc[1])) + x_dist = math.cos(math.radians(loc[0])) * math.sin(math.radians(loc2[0])) + - math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) + * math.cos(math.radians(loc2[1] - loc[1])) bearing = (math.degrees(math.atan2(y_dist, x_dist)) + 360) % 360 embed = cmn.embed_factory(ctx) diff --git a/exts/qrz.py b/exts/qrz.py index 825e60e..166dac8 100644 --- a/exts/qrz.py +++ b/exts/qrz.py @@ -133,8 +133,7 @@ def qrz_process_info(data: dict): state = f', {data["state"]}' else: state = '' - address = data.get('addr1', '') + '\n' + data.get('addr2', '') + \ - state + ' ' + data.get('zip', '') + address = data.get('addr1', '') + '\n' + data.get('addr2', '') + state + ' ' + data.get('zip', '') address = address.strip() if address == '': address = None diff --git a/exts/study.py b/exts/study.py index fb8298e..faf40a0 100644 --- a/exts/study.py +++ b/exts/study.py @@ -75,10 +75,10 @@ class StudyCog(commands.Cog): embed.description = self.source embed.colour = cmn.colours.good embed.add_field(name='Question:', value=question['text'], inline=False) - embed.add_field(name='Answers:', value='**A:** ' + question['answers']['A'] + - '\n**B:** ' + question['answers']['B'] + - '\n**C:** ' + question['answers']['C'] + - '\n**D:** ' + question['answers']['D'], inline=False) + embed.add_field(name='Answers:', value='**A:** ' + question['answers']['A'] + + '\n**B:** ' + question['answers']['B'] + + '\n**C:** ' + question['answers']['C'] + + '\n**D:** ' + question['answers']['D'], inline=False) embed.add_field(name='Answer:', value='Type _?rqa_ for answer', inline=False) if 'image' in question: image_url = f'https://hamstudy.org/_1330011/images/{selected_pool.split("_",1)[1]}/{question["image"]}' From ea8c3a9045159f5b0719ee024b6e4ed26d8fcb38 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Wed, 25 Dec 2019 02:52:14 -0500 Subject: [PATCH 4/5] in dent we trust --- exts/grid.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exts/grid.py b/exts/grid.py index 2f2d41b..03305ba 100644 --- a/exts/grid.py +++ b/exts/grid.py @@ -84,8 +84,8 @@ If two grid squares are given, the distance and azimuth between them is calculat d_lat = math.radians(loc2[0] - loc[0]) d_lon = math.radians(loc2[1] - loc[1]) a = math.sin(d_lat/2) ** 2 - + math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) - * math.sin(d_lon/2) ** 2 + a += math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) + a *= math.sin(d_lon/2) ** 2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) d = radius * c d_mi = 0.6213712 * d @@ -93,8 +93,8 @@ If two grid squares are given, the distance and azimuth between them is calculat # Bearing y_dist = math.sin(math.radians(loc2[1]-loc[1])) * math.cos(math.radians(loc2[0])) x_dist = math.cos(math.radians(loc[0])) * math.sin(math.radians(loc2[0])) - - math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) - * math.cos(math.radians(loc2[1] - loc[1])) + x_dist -= math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) + x_dist *= math.cos(math.radians(loc2[1] - loc[1])) bearing = (math.degrees(math.atan2(y_dist, x_dist)) + 360) % 360 embed = cmn.embed_factory(ctx) From 74558c7f27f42fcfd79e4feb8317dbd961d165cb Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 31 Dec 2019 01:13:45 -0500 Subject: [PATCH 5/5] fix regression in grid (continuations) --- exts/grid.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/exts/grid.py b/exts/grid.py index 03305ba..1a9366f 100644 --- a/exts/grid.py +++ b/exts/grid.py @@ -83,18 +83,21 @@ If two grid squares are given, the distance and azimuth between them is calculat # Haversine formula d_lat = math.radians(loc2[0] - loc[0]) d_lon = math.radians(loc2[1] - loc[1]) - a = math.sin(d_lat/2) ** 2 - a += math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) - a *= math.sin(d_lon/2) ** 2 + a = (math.sin(d_lat/2) ** 2 + + math.cos(math.radians(loc[0])) + * math.cos(math.radians(loc2[0])) + * math.sin(d_lon/2) ** 2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) d = radius * c d_mi = 0.6213712 * d # Bearing y_dist = math.sin(math.radians(loc2[1]-loc[1])) * math.cos(math.radians(loc2[0])) - x_dist = math.cos(math.radians(loc[0])) * math.sin(math.radians(loc2[0])) - x_dist -= math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) - x_dist *= math.cos(math.radians(loc2[1] - loc[1])) + x_dist = (math.cos(math.radians(loc[0])) + * math.sin(math.radians(loc2[0])) + - math.sin(math.radians(loc[0])) + * math.cos(math.radians(loc2[0])) + * math.cos(math.radians(loc2[1] - loc[1]))) bearing = (math.degrees(math.atan2(y_dist, x_dist)) + 360) % 360 embed = cmn.embed_factory(ctx)