From 2da5cc8f299dcc4046d527c48defac5503117502 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 1 Jun 2023 13:53:45 -0700 Subject: [PATCH] update /ship command to work with new wiki layout --- app/star_citizen.py | 105 +++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 70 deletions(-) diff --git a/app/star_citizen.py b/app/star_citizen.py index 1c6263b7..ebe50e78 100644 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -28,11 +28,12 @@ async def get_ship(ship_name): # .replace("400px", "1920px") ) - ship_name_on_page = ( - soup.find("tr", {"class": "infobox-title"}).findNext("th").text - ) + ship_name_on_page = soup.find("span", {"class": "mw-page-title-main"}).text + manufacturer = ( - soup.find("tr", {"class": "data-manufacturer"}).findNext("a").text + soup.find("div", {"class": "infobox__subtitle infobox__data"}) + .findNext("a") + .text ) embed.set_thumbnail( @@ -45,52 +46,42 @@ async def get_ship(ship_name): ) ship_role = ( - soup.find("tr", {"class": "data-role infobox-data infobox-col2"}) - .findNext("td") + soup.find("div", {"class": "infobox__label"}, string="Role") + .findNext("div") .text ) embed.add_field(name="**Role**", value=ship_role) - ingame_price = ( - soup.find("div", {"class": "data-buycost infobox-data infobox-col2"}) - .find("div", {"class": "infobox-data__value"}) - .text - ) + ingame_price = soup.find("td", {"class": "Price smwtype_qty"}).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: 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( name="**Ingame Price**", value=price, 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: pledge_price = ( - soup.find("div", {"class": "data-pledgecost infobox-data infobox-col4"}) - .find("div", {"class": "infobox-data__value"}) + soup.find("div", {"class": "infobox__label"}, string="Standalone") + .findNext("span", {"class": "smwtext"}) .text ) except Exception: @@ -104,7 +95,7 @@ async def get_ship(ship_name): embed.add_field( name="**Pledge Price**", - value="[%s](%s)" % (pledge_price, pledge_store_link), + value="[%s](%s#buying-options)" % (pledge_price, pledge_store_link), inline=True, ) except Exception: @@ -117,28 +108,10 @@ async def get_ship(ship_name): # embed.add_field(name="-------", value="", inline=False) # embed.add_field(name="**Description**", value=ship["description"], 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: cargo_capacity = ( - soup.find( - "tr", {"class": "data-cargocapacity infobox-data infobox-col4"} - ) - .findChildren("td")[0] + soup.find("div", {"class": "infobox__label"}, string="Cargo") + .findNext("span", {"class": "smwtext"}) .text ) except Exception: @@ -148,8 +121,8 @@ async def get_ship(ship_name): try: crew_size = ( - soup.find("tr", {"class": "data-crew infobox-data infobox-col4"}) - .findChildren("td")[0] + soup.find("div", {"class": "infobox__label"}, string="Crew") + .findNext("div", {"class": "infobox__data"}) .text ) 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="**Gun Racks**", - value="Yes" if "gun rack" in response.lower() else "No", - inline=True, - ) embed.add_field(name="-------", value="", inline=False) try: claim_time = ( - soup.find("div", {"class": "data-claimtime infobox-data infobox-col4"}) - .find("div", {"class": "infobox-data__value"}) + soup.find("div", {"class": "infobox__label"}, string="Claim") + .findNext("div", {"class": "infobox__data"}) .text ) except Exception: @@ -177,10 +145,8 @@ async def get_ship(ship_name): try: expedited_claim_time = ( - soup.find( - "div", {"class": "data-expeditetime infobox-data infobox-col4"} - ) - .find("div", {"class": "infobox-data__value"}) + soup.find("div", {"class": "infobox__label"}, string="Expedite") + .findNext("div", {"class": "infobox__data"}) .text ) except Exception: @@ -191,10 +157,8 @@ async def get_ship(ship_name): try: expedite_fee = ( - soup.find( - "div", {"class": "data-expeditecost infobox-data infobox-col2"} - ) - .find("div", {"class": "infobox-data__value"}) + soup.find("div", {"class": "infobox__label"}, string="Expedite fee") + .findNext("div", {"class": "infobox__data"}) .text ) except Exception: @@ -209,6 +173,7 @@ async def get_ship(ship_name): embed.set_image(url=ship_image) except Exception as e: + print(e) embed = discord.Embed(description="❌", color=discord.Color.red(), type="rich") embed.add_field( name="**Could not find that ship**",