From 02433947b62aa71954cb789c2405de5ed6bfd690 Mon Sep 17 00:00:00 2001 From: Abigail Gold Date: Sun, 20 Oct 2019 14:44:29 -0400 Subject: [PATCH] add error message, retry on session timeout --- cogs/qrzcog.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cogs/qrzcog.py b/cogs/qrzcog.py index a1b085b..785bfa0 100644 --- a/cogs/qrzcog.py +++ b/cogs/qrzcog.py @@ -41,17 +41,29 @@ 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_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()} resp_xml_session = resp_xml.xpath('/x:QRZDatabase/x:Session', - namespaces={'x':'http://xmldata.qrz.com'}) + 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']: await self.get_session() + await self._qrz_lookup(ctx, call) + return + if 'Not found' in resp_session['Error']: + embed = discord.Embed(title=f"QRZ Data for {call.upper()}", + colour=self.gs.colours.bad, + description='No data found!', + timestamp=datetime.utcnow()) + embed.set_footer(text=ctx.author.name, + icon_url=str(ctx.author.avatar_url)) + await ctx.send(embed=embed) + return raise ValueError(resp_session['Error']) + 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 = discord.Embed(title=f"QRZ Data for {resp_data['call']}", colour=self.gs.colours.good, url=f'http://www.qrz.com/db/{resp_data["call"]}',