From 2113203be1df656ad9f16126cbf100dc8c2e26f1 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sun, 7 May 2023 13:09:35 -0700 Subject: [PATCH] Fix errors by just returning N/A --- app/star_citizen.py | 79 +++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/app/star_citizen.py b/app/star_citizen.py index 49e410bf..89d4eab9 100644 --- a/app/star_citizen.py +++ b/app/star_citizen.py @@ -90,37 +90,55 @@ async def get_ship(ship_name): # embed.add_field(name="**Description**", value=ship["description"], inline=False) embed.add_field(name="-------", value="", inline=False) - stowage_capacity = ( - soup.find("tr", {"class": "data-stowagespace infobox-data infobox-col2"}) - .findChildren("td")[0] - .text - ) + 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 ) - cargo_capacity = ( - soup.find("tr", {"class": "data-cargocapacity infobox-data infobox-col4"}) - .findChildren("td")[0] - .text - ) + try: + cargo_capacity = ( + soup.find( + "tr", {"class": "data-cargocapacity infobox-data infobox-col4"} + ) + .findChildren("td")[0] + .text + ) + except Exception: + cargo_capacity = "N/A" embed.add_field(name="**Cargo Capacity**", value=cargo_capacity, inline=True) - crew_size = ( - soup.find("tr", {"class": "data-crew infobox-data infobox-col4"}) - .findChildren("td")[0] - .text - ) + try: + crew_size = ( + soup.find("tr", {"class": "data-crew infobox-data infobox-col4"}) + .findChildren("td")[0] + .text + ) + except Exception: + crew_size = "N/A" + embed.add_field(name="**Crew Size**", value=crew_size, inline=True) embed.add_field(name="-------", value="", inline=False) - claim_time = ( - soup.find("div", {"class": "data-claimtime infobox-data infobox-col4"}) - .find("div", {"class": "infobox-data__value"}) - .text - ) + try: + claim_time = ( + soup.find("div", {"class": "data-claimtime infobox-data infobox-col4"}) + .find("div", {"class": "infobox-data__value"}) + .text + ) + except Exception: + claim_time = "N/A" + embed.add_field(name="**Insurance claim time**", value=claim_time, inline=True) try: @@ -131,24 +149,24 @@ async def get_ship(ship_name): .find("div", {"class": "infobox-data__value"}) .text ) - embed.add_field( - name="**Expedite claim time**", value=expedited_claim_time, inline=True - ) - except Exception as e: - print(e) + except Exception: + expedited_claim_time = "N/A" + embed.add_field( + name="**Expedite claim time**", value=expedited_claim_time, inline=True + ) try: - expedited_fee = ( + expedite_fee = ( soup.find( "div", {"class": "data-expeditecost infobox-data infobox-col2"} ) .find("div", {"class": "infobox-data__value"}) .text ) - embed.add_field(name="**Expedite Fee**", value=expedited_fee, inline=True) - except Exception as e: - print(e) - pass + except Exception: + expedite_fee = "N/A" + + embed.add_field(name="**Expedite Fee**", value=expedite_fee, inline=True) embed.add_field( name="**Link**", value="%s%s" % (wiki_url, wiki_ship_name), inline=False @@ -164,7 +182,6 @@ async def get_ship(ship_name): % ship_name, inline=True, ) - print(e) return embed return embed