From c74736966733b0e8bf34436d718213253227a503 Mon Sep 17 00:00:00 2001 From: bobloy Date: Mon, 31 Aug 2020 11:37:46 -0400 Subject: [PATCH] Merge missing changes, better error handling --- lovecalculator/lovecalculator.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lovecalculator/lovecalculator.py b/lovecalculator/lovecalculator.py index 4425cf7..95e9f97 100644 --- a/lovecalculator/lovecalculator.py +++ b/lovecalculator/lovecalculator.py @@ -36,14 +36,16 @@ class LoveCalculator(Cog): async with session.get(url) as response: assert response.status == 200 resp = await response.text() + log.debug(f"{resp=}") soup_object = BeautifulSoup(resp, "html.parser") - try: - description = ( - soup_object.find("div", class_="result__score").get_text().strip() - ) - except: + + description = soup_object.find("div", class_="result__score").get_text() + + if description is None: description = "Dr. Love is busy right now" + else: + description = description.strip() result_image = soup_object.find("img", class_="result__image").get("src") @@ -61,6 +63,11 @@ class LoveCalculator(Cog): except: title = "Dr. Love has left a note for you." - em = discord.Embed(title=title, description=result_text, color=discord.Color.red(), url=f"https://www.lovecalculator.com/{result_image}") + em = discord.Embed( + title=title, + description=result_text, + color=discord.Color.red(), + url=f"https://www.lovecalculator.com/{result_image}", + ) await ctx.send(embed=em)