From 7a6bfb64a764a436442157cf4867a62d350e6c72 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Fri, 21 Mar 2025 18:46:16 -0700 Subject: [PATCH] use paldex.gg for pal info --- app/cogs/palworld.py | 90 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/app/cogs/palworld.py b/app/cogs/palworld.py index ac54dc3a..3b983ac0 100755 --- a/app/cogs/palworld.py +++ b/app/cogs/palworld.py @@ -21,21 +21,22 @@ class PalWorld(commands.Cog): import requests from bs4 import BeautifulSoup - all_pals = [] + url = "https://palworld.gg/pals" + response = requests.get(url).text + soup = BeautifulSoup(response, "html.parser") - url = "https://paldex.io/palworld/pals/" - response = requests.get(url) + pal_list = [] - soup = BeautifulSoup(response.text, "html.parser") + all_pals = soup.find_all("div", class_="pal") + try: + for pal in all_pals: + name = pal.find("div", class_="name").text.split("#", 1)[0].strip() - x = soup.find_all( - "p", - class_="text-base lg:text-lg group-hover:underline underline-offset-4 text-center", - ) - for pal in x: - all_pals.append(pal.text) + pal_list.append(name) + except: + pass - return sorted(set(all_pals)) + return pal_list @palworld.command( guild_ids=None, @@ -60,18 +61,17 @@ class PalWorld(commands.Cog): description="Pal to look up", ), ): - pal_url = "https://paldex.io/palworld/pals/%s/" % pal.lower().replace(" ", "-") + pal_url = f"https://palworld.gg/pal/{pal.lower().replace(' ', '-')}" response = requests.get(pal_url) soup = BeautifulSoup(response.text, "html.parser") elements = {} + # Get the pal's primary element + pal_elements_div = soup.find("div", class_="elements") - pal_elements = soup.find("div", class_="flex flex-row flex-wrap gap-3") - for div in pal_elements: - pal_element_badge = div.find("img", class_="rounded-full w-8 h-8 m-2") - element_type = pal_element_badge.find_next("p").text - element_icon = pal_element_badge["src"] - elements[element_type] = element_icon + element_icon = "https://palworld.gg" + pal_elements_div.find("img")["src"] + element_type = pal_elements_div.text + elements[element_type] = element_icon primary_element = list(elements.keys())[0] @@ -84,7 +84,7 @@ class PalWorld(commands.Cog): "Fire": discord.Color.red(), "Leaf": discord.Color.green(), "Ice": discord.Color.blue(), - "Normal": discord.Color.lighter_grey(), + "Neutral": discord.Color.lighter_grey(), "Water": discord.Color.dark_blue(), } @@ -102,10 +102,8 @@ class PalWorld(commands.Cog): ) embed.set_thumbnail( - url=soup.find( - "img", - class_="rounded-full w-32 h-32 border-2 border-amber-500 aspect-square", - )["src"] + url="https://palworld.gg" + + soup.find("div", class_="image").find_next("img")["src"] ) # embed.add_field(name="Work Skills", value="-----", inline=False) @@ -115,9 +113,9 @@ class PalWorld(commands.Cog): "Farming": "🚜", "Gathering": "🍃", "Generating Electricity": "⚡️", - "Handwork": "🤚", + "Handiwork": "🤚", "Kindling": "🔥", - "Lumbering": "🪵", + "Deforesting": "🪵", "Medicine Production": "💉", "Mining": "⛏️", "Planting": "🌱", @@ -125,15 +123,14 @@ class PalWorld(commands.Cog): "Watering": "💦", } - skill_table = soup.find("div", class_="flex flex-col gap-2") - for div in skill_table.find_all( - "div", class_=re.compile(".*border-amber-300\s+break-all") - ): - skill_name = div.find("p", class_="text-base sm:text-lg").text - skill_level = div.find( - "p", class_="text-base sm:text-lg mr-2 md:mr-4" - ).text.split("Lv")[-1] + work_suit = ( + soup.find("h2", string="Work Suitability") + .find_next("div", class_="items") + .find_all("div", class_="active item") + ) + for skill in work_suit: + skill_name, skill_level = skill.text.split("Lv") embed.add_field( name=skills_emojis[skill_name] + " " + skill_name, value="%s" % (int(skill_level) * "⭐️"), @@ -142,27 +139,28 @@ class PalWorld(commands.Cog): # Partner Skill embed.add_field(name="Partner Skill", value="-----", inline=False) - skill_name = soup.find("h2", string="Partner Skill").find_next( - "p", class_=re.compile(".*text-xl.*") - ) - skill_description = skill_name.find_next("p", class_="text-lg mr-4").text + skill = soup.find("div", class_="passive skills") + skill_name = skill.find_next("div", class_="name").text + skill_description = skill.find_next("p").text + embed.add_field( - name=skill_name.text, + name=skill_name, value=skill_description, inline=False, ) # Drops embed.add_field(name="Drops", value="-----", inline=False) - for div in soup.find_all( - "div", - class_="inline-flex flex-col gap-1 items-center bg-black-300 border border-amber-300 break-all p-2", - ): - item = div.text - item_name = item.split("Quantity")[0].split("Drop Chance") - amount = item.split("Quantity")[-1].split("Drop Chance") + drops = [ + x.text + for x in soup.find("h2", string="Possible Drops") + .find_next("table") + .find_all("div", class_="name") + ] + + for item in drops: embed.add_field( - name=" ".join(item_name), + name=item, value="", inline=False, )