update /ship command to work with new wiki layout
This commit is contained in:
parent
579a48fa65
commit
e71baf2b7e
@ -28,11 +28,12 @@ async def get_ship(ship_name):
|
|||||||
# .replace("400px", "1920px")
|
# .replace("400px", "1920px")
|
||||||
)
|
)
|
||||||
|
|
||||||
ship_name_on_page = (
|
ship_name_on_page = soup.find("span", {"class": "mw-page-title-main"}).text
|
||||||
soup.find("tr", {"class": "infobox-title"}).findNext("th").text
|
|
||||||
)
|
|
||||||
manufacturer = (
|
manufacturer = (
|
||||||
soup.find("tr", {"class": "data-manufacturer"}).findNext("a").text
|
soup.find("div", {"class": "infobox__subtitle infobox__data"})
|
||||||
|
.findNext("a")
|
||||||
|
.text
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.set_thumbnail(
|
embed.set_thumbnail(
|
||||||
@ -45,52 +46,42 @@ async def get_ship(ship_name):
|
|||||||
)
|
)
|
||||||
|
|
||||||
ship_role = (
|
ship_role = (
|
||||||
soup.find("tr", {"class": "data-role infobox-data infobox-col2"})
|
soup.find("div", {"class": "infobox__label"}, string="Role")
|
||||||
.findNext("td")
|
.findNext("div")
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(name="**Role**", value=ship_role)
|
embed.add_field(name="**Role**", value=ship_role)
|
||||||
|
|
||||||
ingame_price = (
|
ingame_price = soup.find("td", {"class": "Price smwtype_qty"}).text
|
||||||
soup.find("div", {"class": "data-buycost infobox-data infobox-col2"})
|
|
||||||
.find("div", {"class": "infobox-data__value"})
|
|
||||||
.text
|
|
||||||
)
|
|
||||||
|
|
||||||
price = "[%s](%s%s#Buying)" % (ingame_price, wiki_url, wiki_ship_name)
|
price = "[%s](%s%s#Universe_availability)" % (
|
||||||
|
ingame_price,
|
||||||
|
wiki_url,
|
||||||
|
wiki_ship_name,
|
||||||
|
)
|
||||||
|
|
||||||
if "Not available" in ingame_price:
|
if "Not available" in ingame_price:
|
||||||
price = "N/A"
|
price = "N/A"
|
||||||
|
|
||||||
## Hideous code for "where to buy" in game
|
|
||||||
# table = soup.find("span", {"id": "Buying"}).findNext(
|
|
||||||
# "table", {"class": "wikitable"}
|
|
||||||
# )
|
|
||||||
|
|
||||||
# locations = [x.text.replace("\n", "") for x in table.find_all("th")]
|
|
||||||
# prices = [x.text.replace("\n", "") for x in table.find_all("td")]
|
|
||||||
# zip_list = zip(locations, prices)
|
|
||||||
|
|
||||||
# result = list(zip_list)
|
|
||||||
# ingame_price = [x for x in result if "Unavailable" not in x]
|
|
||||||
|
|
||||||
# for x in ingame_price:
|
|
||||||
# ingame_price = " ".join(x) + " aUEC"
|
|
||||||
|
|
||||||
# if not len(ingame_price):
|
|
||||||
# ingame_price = "No in-game price available"
|
|
||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="**Ingame Price**",
|
name="**Ingame Price**",
|
||||||
value=price,
|
value=price,
|
||||||
inline=True,
|
inline=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
buy_location = soup.find_all("td", {"class": "Location smwtype_wpg"})
|
||||||
|
|
||||||
|
embed.add_field(
|
||||||
|
name="**Where to buy**",
|
||||||
|
value=", ".join(str(x.text) for x in buy_location),
|
||||||
|
inline=True,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
pledge_price = (
|
pledge_price = (
|
||||||
soup.find("div", {"class": "data-pledgecost infobox-data infobox-col4"})
|
soup.find("div", {"class": "infobox__label"}, string="Standalone")
|
||||||
.find("div", {"class": "infobox-data__value"})
|
.findNext("span", {"class": "smwtext"})
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -104,7 +95,7 @@ async def get_ship(ship_name):
|
|||||||
|
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="**Pledge Price**",
|
name="**Pledge Price**",
|
||||||
value="[%s](%s)" % (pledge_price, pledge_store_link),
|
value="[%s](%s#buying-options)" % (pledge_price, pledge_store_link),
|
||||||
inline=True,
|
inline=True,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -117,28 +108,10 @@ async def get_ship(ship_name):
|
|||||||
# embed.add_field(name="-------", value="", inline=False)
|
# embed.add_field(name="-------", value="", inline=False)
|
||||||
# embed.add_field(name="**Description**", value=ship["description"], inline=False)
|
# embed.add_field(name="**Description**", value=ship["description"], inline=False)
|
||||||
embed.add_field(name="-------", value="", inline=False)
|
embed.add_field(name="-------", value="", inline=False)
|
||||||
|
|
||||||
try:
|
|
||||||
stowage_capacity = (
|
|
||||||
soup.find(
|
|
||||||
"tr", {"class": "data-stowagespace infobox-data infobox-col2"}
|
|
||||||
)
|
|
||||||
.findChildren("td")[0]
|
|
||||||
.text
|
|
||||||
)
|
|
||||||
except Exception:
|
|
||||||
stowage_capacity = "N/A"
|
|
||||||
|
|
||||||
embed.add_field(
|
|
||||||
name="**Stowage Capacity**", value=stowage_capacity, inline=True
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cargo_capacity = (
|
cargo_capacity = (
|
||||||
soup.find(
|
soup.find("div", {"class": "infobox__label"}, string="Cargo")
|
||||||
"tr", {"class": "data-cargocapacity infobox-data infobox-col4"}
|
.findNext("span", {"class": "smwtext"})
|
||||||
)
|
|
||||||
.findChildren("td")[0]
|
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -148,8 +121,8 @@ async def get_ship(ship_name):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
crew_size = (
|
crew_size = (
|
||||||
soup.find("tr", {"class": "data-crew infobox-data infobox-col4"})
|
soup.find("div", {"class": "infobox__label"}, string="Crew")
|
||||||
.findChildren("td")[0]
|
.findNext("div", {"class": "infobox__data"})
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -157,17 +130,12 @@ async def get_ship(ship_name):
|
|||||||
|
|
||||||
embed.add_field(name="**Crew Size**", value=crew_size, inline=True)
|
embed.add_field(name="**Crew Size**", value=crew_size, inline=True)
|
||||||
|
|
||||||
embed.add_field(
|
|
||||||
name="**Gun Racks**",
|
|
||||||
value="Yes" if "gun rack" in response.lower() else "No",
|
|
||||||
inline=True,
|
|
||||||
)
|
|
||||||
embed.add_field(name="-------", value="", inline=False)
|
embed.add_field(name="-------", value="", inline=False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
claim_time = (
|
claim_time = (
|
||||||
soup.find("div", {"class": "data-claimtime infobox-data infobox-col4"})
|
soup.find("div", {"class": "infobox__label"}, string="Claim")
|
||||||
.find("div", {"class": "infobox-data__value"})
|
.findNext("div", {"class": "infobox__data"})
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -177,10 +145,8 @@ async def get_ship(ship_name):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
expedited_claim_time = (
|
expedited_claim_time = (
|
||||||
soup.find(
|
soup.find("div", {"class": "infobox__label"}, string="Expedite")
|
||||||
"div", {"class": "data-expeditetime infobox-data infobox-col4"}
|
.findNext("div", {"class": "infobox__data"})
|
||||||
)
|
|
||||||
.find("div", {"class": "infobox-data__value"})
|
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -191,10 +157,8 @@ async def get_ship(ship_name):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
expedite_fee = (
|
expedite_fee = (
|
||||||
soup.find(
|
soup.find("div", {"class": "infobox__label"}, string="Expedite fee")
|
||||||
"div", {"class": "data-expeditecost infobox-data infobox-col2"}
|
.findNext("div", {"class": "infobox__data"})
|
||||||
)
|
|
||||||
.find("div", {"class": "infobox-data__value"})
|
|
||||||
.text
|
.text
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -209,6 +173,7 @@ async def get_ship(ship_name):
|
|||||||
embed.set_image(url=ship_image)
|
embed.set_image(url=ship_image)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
embed = discord.Embed(description="❌", color=discord.Color.red(), type="rich")
|
embed = discord.Embed(description="❌", color=discord.Color.red(), type="rich")
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="**Could not find that ship**",
|
name="**Could not find that ship**",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user