From 928b1cad07165b73b89406036044bdc962ac2305 Mon Sep 17 00:00:00 2001 From: Luke R Date: Wed, 26 Feb 2025 15:11:13 -0800 Subject: [PATCH] make excuse use beautiful soup --- app/cogs/cheeky_functions.py | 4 ++-- app/excuse.py | 27 +++++++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/cogs/cheeky_functions.py b/app/cogs/cheeky_functions.py index c1f9c1c8..40f6d169 100755 --- a/app/cogs/cheeky_functions.py +++ b/app/cogs/cheeky_functions.py @@ -161,11 +161,11 @@ class Cheeky(commands.Cog): await ctx.respond(embed=dice.roll(number_of_die, sides, number_to_add)) - @commands.command(name="excuse") + @commands.slash_command(name="excuse") async def excuse(self, ctx: commands.Context): import excuse - await ctx.reply(excuse.get_excuse()) + await ctx.respond(excuse.get_excuse()) async def get_all_meme_templates(ctx: discord.AutocompleteContext): """ diff --git a/app/excuse.py b/app/excuse.py index a111947a..d73f5592 100755 --- a/app/excuse.py +++ b/app/excuse.py @@ -3,11 +3,26 @@ import requests def get_excuse(): - url = requests.get("http://www.devexcuses.com") - soup = BeautifulSoup(url.content, features="html.parser") + """ + Fetches a random developer excuse from devexcuses.com - return "```{}```".format( - str(soup.find("p", {"class": "excuse"}).contents[0]) - .split(">")[1] - .split(" tag inside the

+ excuse_link = excuse_element.find("a") + excuse_text = ( + excuse_link.text.strip() if excuse_link else excuse_element.text.strip() ) + + return f"```{excuse_text}```"