From df44f2327363607ecba1c880bb8cb0949f3217c0 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 1 Jun 2023 17:54:19 -0700 Subject: [PATCH] Fixing price lookups for ships with a try except --- app/star_citizen.py | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/app/star_citizen.py b/app/star_citizen.py index b28ad83e..25c394d8 100644 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -29,12 +29,14 @@ async def get_ship(ship_name): ) ship_name_on_page = soup.find("span", {"class": "mw-page-title-main"}).text - - manufacturer = ( - soup.find("div", {"class": "infobox__subtitle infobox__data"}) - .findNext("a") - .text - ) + try: + manufacturer = ( + soup.find("div", {"class": "infobox__subtitle infobox__data"}) + .findNext("a") + .text + ) + except: + manufacturer = "" embed.set_thumbnail( url="https://media.robertsspaceindustries.com/t0q21kbb3zrpt/source.png" @@ -45,23 +47,29 @@ async def get_ship(ship_name): url="%s%s" % (wiki_url, wiki_ship_name), ) - ship_role = ( - soup.find("div", {"class": "infobox__label"}, string="Role") - .findNext("div") - .text - ) + try: + ship_role = ( + soup.find("div", {"class": "infobox__label"}, string="Role") + .findNext("div") + .text + ) + except: + ship_role = "" embed.add_field(name="**Role**", value=ship_role) - ingame_price = soup.find("td", {"class": "Price smwtype_qty"}).text + try: + ingame_price = soup.find("td", {"class": "Price smwtype_qty"}).text - price = "[%s](%s%s#Universe_availability)" % ( - 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" + except: price = "N/A" embed.add_field(