Reduce copy pasted code for getting the ship dimensions

This commit is contained in:
Luke Robles 2024-11-10 21:14:35 -08:00
parent 5a66684363
commit 8168f4bc73

View File

@ -413,42 +413,19 @@ async def get_ship(ship_name):
embed.add_field(name="**Expedite Fee**", value=expedite_fee, inline=True)
embed.add_field(name="-------", value="", inline=False)
try:
length = (
soup.find(
"div", {"class": "template-dimensions-label"}, string="Length"
dimensions = ["Length", "Width", "Height"]
for dimension in dimensions:
try:
value = (
soup.find(
"div", {"class": "template-dimensions-label"}, string=dimension
)
.findNext("div", {"class": "template-dimensions-data"})
.text
)
.findNext("div", {"class": "template-dimensions-data"})
.text
)
except Exception:
length = "N/A"
embed.add_field(name="**Length**", value=length, inline=True)
try:
width = (
soup.find("div", {"class": "template-dimensions-label"}, string="Width")
.findNext("div", {"class": "template-dimensions-data"})
.text
)
except Exception:
width = "N/A"
embed.add_field(name="**Width**", value=width, inline=True)
try:
height = (
soup.find(
"div", {"class": "template-dimensions-label"}, string="Height"
)
.findNext("div", {"class": "template-dimensions-data"})
.text
)
except Exception:
height = "N/A"
embed.add_field(name="**Height**", value=height, inline=True)
except Exception:
value = "N/A"
embed.add_field(name=f"**{dimension}**", value=value, inline=True)
embed.add_field(
name="**Link**", value="%s%s" % (wiki_url, wiki_ship_name), inline=False